steelbreeze / state.js

DEPRECATED, please see @steelbreeze/state
https://github.com/steelbreeze/state
MIT License
324 stars 39 forks source link

About async exit and entry,parallel regions of one state #19

Closed dorado-lmz closed 8 years ago

dorado-lmz commented 8 years ago
thanks for your reply of last pull request

And this time i deal with some other problems.


so,now it will be useful,for example .entry(function(message, instance,history,cb){setTimeout(console.log(111);cb(null,1);},1000)}); it can be find in test/asyncEntry.js line 9. you can node asyncEntry.js to see the result.in addation to,you also can use cb("entry model error",1); to report an error.

  • i also found statechart of UML has concurrency.it means two regions can execute parallelly.so i use the test file p3pp3r.js,you can exectue it ,it will be executed parallelly.
mesmo commented 8 years ago

Keeping the code completely synchronous was another deliberate design decision, as I do not want to impose any particular asynchronous strategy on my users - what's good for one is likely to be bad for another.

What I'd suggest for async operations is that you keep a reference/id to the async task in the state machine instance and either cancel the task or wait for it to complete explicitly. E.g. WindowTimers.setTimeout returns a timeoutID that can be subsequently passed into WindowTimers.clearTimeout.

Re. orthogonal (parallel) regions, this is not a means for concurrency at runtime; this is used to have independent substates of a machine being able to react independently to the same message.