move addDelayedEvent to trigger after the delay finishes #8299
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.
Problem
Delays would trigger isDelayed as soon as they scheduled the delayed task, rather than when the delayed task begins. Since isDelayed cannot differentiate between Triggers, this meant that one trigger could schedule a delay and a second, undelayed, trigger would think it was delayed too!
This PR does NOT fix this issue! It simply mitigates the issue so that the user isn't impacted by it. The delay api still needs to be updated when proper runtime context is implemented.
Solution
Moving the addDelayedEvent call to after the delay is complete ensures that non-delayed code can run as normal, but still ensures delayed code is ran as delayed code. I believe this is safe, but if anyone can think up a counterexample please comment it.
Testing Completed
Manual testing confirms this functions properly, but I did not do a comprehensive check of behaviors. Automated tests can't handle delays so this can't be tested automatically.
Supporting Information
Completes: none
Related: #8298