Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Supply.Promise, channeling from jnthn++
  • Loading branch information
lizmat committed Apr 28, 2014
1 parent c154152 commit 1717d57
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/core/Supply.pm
Expand Up @@ -77,6 +77,32 @@ my role Supply {
$c
}

method Promise() {
my $l = Lock.new;
my $p = Promise.new;
my $v = $p.vow;
my $t = self.tap(
-> \val {
$l.protect( {
if $p.status == Planned {
$v.keep(val);
$t.close()
}
} );
},
done => { $v.break("No value received") },
quit => -> \ex {
$l.protect( {
if $p.status == Planned {
$v.break(ex);
$t.close()
}
} );
},
);
$p
}

method list() {
# Use a Channel to handle any asynchrony.
my $c = self.Channel;
Expand Down

0 comments on commit 1717d57

Please sign in to comment.