Skip to content

Commit

Permalink
Don't resume from an enqueued task if interrupted (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
natefaubion committed Aug 24, 2018
1 parent 5450756 commit f6d95e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Effect/Aff.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ var Aff = function () {
}
runTick++;
Scheduler.enqueue(function () {
// It's possible to interrupt the fiber between enqueuing and
// resuming, so we need to check that the runTick is still
// valid.
if (runTick !== localRunTick + 1) {
return;
}
status = STEP_RESULT;
step = result;
run(runTick);
Expand Down
8 changes: 8 additions & 0 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,13 @@ test_regression_bracket_catch_cleanup = assert "regression/bracket-catch-cleanup
(\_ throwError (error "Nope."))
pure $ lmap message res == Left "Nope."

test_regression_kill_sync_async Aff Unit
test_regression_kill_sync_async = assert "regression/kill-sync-async" do
ref ← newRef ""
f1 ← forkAff $ makeAff \k -> k (Left (error "Boom.")) *> mempty
killFiber (error "Nope.") f1
pure true

main Effect Unit
main = do
test_pure
Expand Down Expand Up @@ -707,3 +714,4 @@ main = do
test_regression_return_fork
test_regression_par_apply_async_canceler
test_regression_bracket_catch_cleanup
test_regression_kill_sync_async

0 comments on commit f6d95e9

Please sign in to comment.