Skip to content

Fix ParAff cancellation #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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