No createTimer
if TimerService
disposed (STANFORD-65)
#241
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.
Pair with Stanford SMSVP PR.
Each of the two calls to
createTimer
inTimerService
is gated behind at least one asynchronous request, eitherTimerService.getCurrentTime
orTimerService.getState
.TimerService.cancel
doesn't know about either of these async pipelines. That means you can write ...... and it's possible that
timerService.cancel()
will finish beforecreateTimer
is called.This is a problem for the following real code:
When you call
TimerHelper.restartTimer
...cancel
the currentthis.timerService
this.timerService
autoStart
on the newthis.timerService
getChannel
on the newthis.timerService
When you call
TimerHelper.restartTimer
many times quickly (going from step 4 to 1), the later-initiatedcancel
call may finish before the first-initiatedgetChannel
. Since the interval is created at the end ofgetChannel
and cleared duringcancel
, you end up with a dangling interval and no reference to clean it up.So we simply
dispose
at the beginning ofcancelTimer
...... and if the
TimerService
has beendisposed
by the time it's time to start the interval, do nothing: