fix potential issue of statemachine trigger lost #69
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
there exists a tiny gap between finishing iterations of firing queued event and sm.op decrease
If another routine run internalFireQueued in that gap, it will not firing but save trigger in eventqueue and return.
Meanwhile, origin routine will not check event queue again because interations has finished
so such trigger event will be left in queue and wait for later firing trigger to executing.
If no trigger again, this trigger event will wait for ever and break run-to-complete
BTW, it's better not to execute all event in one loop,
which may cause Fire() caller waits for a long time to execute some actions not belong to current trigger.
So, in each loop, try to compare and swap sm.ops from 0 to 1, if failed, let current routine has chance to return.