Skip to content

Commit

Permalink
Fix missing tap close calls.
Browse files Browse the repository at this point in the history
Could lead to resource leaks in certain situations.
  • Loading branch information
jnthn committed Aug 11, 2017
1 parent 76af17a commit c59b986
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/core/Supply.pm
Expand Up @@ -96,11 +96,25 @@ my class Supply does Awaitable {
submethod BUILD(:&!producer!, :&!closing!, :$!scheduler! --> Nil) {}

method tap(&emit, &done, &quit) {
my int $closed = 0;
my $t = Tap.new({
if &!closing {
&!closing() unless $closed++;
}
});
my $p = Supplier.new;
$p.Supply.tap(&emit, :&done, :&quit); # sanitizes
$p.Supply.tap(&emit,
done => {
done();
$t.close();
},
quit => -> \ex {
quit(ex);
$t.close();
});
$!scheduler.cue({ &!producer($p) },
catch => -> \ex { $p.quit(ex) });
Tap.new(&!closing)
$t
}

method live(--> False) { }
Expand Down

0 comments on commit c59b986

Please sign in to comment.