Skip to content

Commit

Permalink
Do not resume after emit by closed supply block
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Sep 27, 2017
1 parent 56193b5 commit 80f883b
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/core/Supply.pm
Expand Up @@ -1833,6 +1833,7 @@ augment class Rakudo::Internals {
$!lock.protect: {
@active = %!active-taps.values;
%!active-taps = ();
$!active = 0;
}
@active
}
Expand Down Expand Up @@ -1919,33 +1920,36 @@ augment class Rakudo::Internals {
method !run-supply-code(&code, \value, $state, &add-whenever) {
my @run-after;
my $queued := $state.run-async-lock.protect-or-queue-on-recursion: {
return unless $state.active > 0;
my &*ADD-WHENEVER = &add-whenever;
my $emitter = {
my \ex := nqp::exception();
my $emit-handler := $state.emit;
$emit-handler(nqp::getpayload(ex)) if $emit-handler.DEFINITE;
nqp::resume(ex)
}
my $done = {
$state.get-and-zero-active();
self!teardown($state);
my $done-handler := $state.done;
$done-handler() if $done-handler.DEFINITE;
}
my $catch = {
my \ex = EXCEPTION(nqp::exception());
$state.get-and-zero-active();
self!teardown($state);
my $quit-handler = $state.quit;
$quit-handler(ex) if $quit-handler;
}
nqp::handle(code(value),
'EMIT', $emitter(),
'DONE', $done(),
'CATCH', $catch(),
'NEXT', 0);
@run-after = $state.awaiter.take-all;
if $state.active > 0 {
my &*ADD-WHENEVER = &add-whenever;
my $emitter = {
if $state.active {
my \ex := nqp::exception();
my $emit-handler := $state.emit;
$emit-handler(nqp::getpayload(ex)) if $emit-handler.DEFINITE;
nqp::resume(ex)
}
}
my $done = {
$state.get-and-zero-active();
self!teardown($state);
my $done-handler := $state.done;
$done-handler() if $done-handler.DEFINITE;
}
my $catch = {
my \ex = EXCEPTION(nqp::exception());
$state.get-and-zero-active();
self!teardown($state);
my $quit-handler = $state.quit;
$quit-handler(ex) if $quit-handler;
}
nqp::handle(code(value),
'EMIT', $emitter(),
'DONE', $done(),
'CATCH', $catch(),
'NEXT', 0);
@run-after = $state.awaiter.take-all;
}
}
if $queued.defined {
$queued.then({ self!run-add-whenever-awaits(@run-after) });
Expand Down

0 comments on commit 80f883b

Please sign in to comment.