Pending transition
Hi,
We have an implementation of the javascript-state-machine, "ts-javascript-state-machine", which seems to be a fork of this repo, for ts.
Be that as it may, I think the question[s] are probably still valid here, where it seems more people might be able to help.
So we have a situation in our program, where we create a state machine:
this.stateMachine = new StateMachine({
init: "init",
transitions: [
{
name: "pollA",
from: "init",
to: "waitState",
},
{
name: "getB",
from: "waitState",
to: "visionState",
},
{
name: "testC",
from: "waitState",
to: "waitState",
},
{
name: "getC",
from: "visionState",
to: "waitState,
},
],
methods: {
onPollA: pollA.bind(this),
onGetB: getB.bind(this),
onTestC: testC.bind(this),
onGetC: getC.bind(this),
},
});
somewhere later in our program we try to conduct a state change by calling a transition:
if (
Adapter.stateMachine.is("waitState") &&
Adapter.stateMachine.can("testC")
) {
process.nextTick(() => {
try {
Adapter.stateMachine.testC();
} catch (err) {
winston.error(
`Error triggering transition 'testC' }`
);
}
});
}
the above code then enters the method testC() and checks of a variable is set, to proceed to the next
state
async function testC(this: Adapter) {
if ( v && Adapter.isRunning && Adapter.stateMachine.can("getC")
) {
process.nextTick(() => {
try {
Adapter.stateMachine.getC;
} catch (err) {
winston.error(
`Error triggering transition 'getC'`
);
}
});
}
Currently, by the time it reaches the above function testC(), it seems that the transition is always pending, and we cannot proceed to call getC.
I've tried now to debug this, but with no success, and i'm not entirely able to reproduce this with a simple example, sorry, but is there anything I can use to debug this ?
I've added an observer function call, to when onAftertestC, which should show me when the transition has ended for testC , and this posts normally via debug trace/output, just before it enters testC function above, and when I query Adapter.stateMachine.can("getC") it returns false, when I ask what state I an in , it says the correct state waitState.
tracing through the debugger, I can see the transition is pending, but i'm not sure why now it's not working anymore ? We've not changed the logical flow of our program, we only added a few extra calls to the program, so there is the possibility something is affecting the event loop, or something, but i'm not super familiar on how to resolve this to be honest...
Any help here would be great, even if just pointers on how to find out, why the transition is pending.
Thanks for reading this far... ;)
I resolved my issue...