Skip to content

Commit f6d95e9

Browse files
authored
Don't resume from an enqueued task if interrupted (#162)
1 parent 5450756 commit f6d95e9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Effect/Aff.js

+6
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ var Aff = function () {
327327
}
328328
runTick++;
329329
Scheduler.enqueue(function () {
330+
// It's possible to interrupt the fiber between enqueuing and
331+
// resuming, so we need to check that the runTick is still
332+
// valid.
333+
if (runTick !== localRunTick + 1) {
334+
return;
335+
}
330336
status = STEP_RESULT;
331337
step = result;
332338
run(runTick);

test/Test/Main.purs

+8
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,13 @@ test_regression_bracket_catch_cleanup = assert "regression/bracket-catch-cleanup
660660
(\_ throwError (error "Nope."))
661661
pure $ lmap message res == Left "Nope."
662662

663+
test_regression_kill_sync_async Aff Unit
664+
test_regression_kill_sync_async = assert "regression/kill-sync-async" do
665+
ref ← newRef ""
666+
f1 ← forkAff $ makeAff \k -> k (Left (error "Boom.")) *> mempty
667+
killFiber (error "Nope.") f1
668+
pure true
669+
663670
main Effect Unit
664671
main = do
665672
test_pure
@@ -707,3 +714,4 @@ main = do
707714
test_regression_return_fork
708715
test_regression_par_apply_async_canceler
709716
test_regression_bracket_catch_cleanup
717+
test_regression_kill_sync_async

0 commit comments

Comments
 (0)