danielgerlag / workflow-es

Workflow / durable task library for Node.js (or modern browsers)
MIT License
201 stars 49 forks source link

Self Transitions and Feedback loops #37

Open king612 opened 5 years ago

king612 commented 5 years ago

Could you please provide guidance on how best to implement a self-transition? That is a state that transitions back to itself? Ideally, it would do this conditionally. So, maybe it transitions to an If that can transition back to the original state?

Geneally, the framework seems to only support acyclic paths through the state machine. Surely you can have a return transition that goes back to a previous state? Would you just 'reinstantiate' that step again in the WF definition?

I suspect it would involve ExecutionResult.branch() but there is apparently no documentation of that nor any samples that use it. The If example also appears to be a once-through with no feedback loop.

Any help would be greatly appreciated. If all workflows have to be acyclical, that would be a dealbreaker for us using it.

danielgerlag commented 5 years ago

It is possible but you have to do it like this currently:

let step1 = builder.startWith(HelloWorld);
let step2 = step1.then(GoodbyeWorld);
step2.thenStep(step1);

On the .net version we did implement a nicer syntax - here: https://github.com/danielgerlag/workflow-core/releases/tag/1.8.3