Skip to content

Commit

Permalink
Fix ParAff cancellation (#131)
Browse files Browse the repository at this point in the history
Fixes #130
  • Loading branch information
natefaubion authored Nov 19, 2017
1 parent 1d2f56e commit a048d9c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Control/Monad/Aff.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,9 @@ var Aff = function () {
joins[jid] = join;

return function() {
delete joins[jid];
if (joins !== null) {
delete joins[jid];
}
};
};
}
Expand Down Expand Up @@ -937,14 +939,20 @@ var Aff = function () {
}

// Cancels the entire tree. If there are already subtrees being canceled,
// we need to first cancel those joins. This is important so that errors
// don't accidentally get swallowed by irrelevant join callbacks.
// we need to first cancel those joins. We will then add fresh joins for
// all pending branches including those that were in the process of being
// canceled.
function cancel(error, cb) {
interrupt = util.left(error);

var innerKills;
for (var kid in kills) {
if (kills.hasOwnProperty(kid)) {
kills[kid]();
innerKills = kills[kid];
for (kid in innerKills) {
if (innerKills.hasOwnProperty(kid)) {
innerKills[kid]();
}
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,25 @@ test_kill_parallel_alt = assert "kill/parallel/alt" do
_ ← try $ joinFiber f2
eq "killedfookilledbardone" <$> readRef ref

test_kill_parallel_alt_finalizer eff. TestAff eff Unit
test_kill_parallel_alt_finalizer = assert "kill/parallel/alt/finalizer" do
ref ← newRef ""
f1 ← forkAff $ sequential $
parallel (delay (Milliseconds 10.0)) <|> parallel do
bracket
(pure unit)
(\_ → do
delay (Milliseconds 10.0)
modifyRef ref (_ <> "killed"))
(\_ → delay (Milliseconds 20.0))
f2 ← forkAff do
delay (Milliseconds 15.0)
killFiber (error "Nope") f1
modifyRef ref (_ <> "done")
_ ← try $ joinFiber f1
_ ← try $ joinFiber f2
eq "killeddone" <$> readRef ref

test_fiber_map eff. TestAff eff Unit
test_fiber_map = assert "fiber/map" do
ref ← newRef 0
Expand Down Expand Up @@ -628,6 +647,7 @@ main = do
test_parallel_alt_sync
test_parallel_mixed
test_kill_parallel_alt
test_kill_parallel_alt_finalizer
test_avar_order
test_efffn
test_fiber_map
Expand Down

0 comments on commit a048d9c

Please sign in to comment.