Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support a :&catch argument for start() and Promise.start()
This allows timely detection of exceptions thrown by tasks
that may not be await'ed for some time (e.g. because they
are background tasks not expected to complete for a long time),
and mirrors the same parameter on ThreadPoolScheduler.cue().
  • Loading branch information
Geoffrey Broadwell committed Mar 26, 2015
1 parent dd13105 commit f5d0bc2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/Promise.pm
Expand Up @@ -155,12 +155,12 @@ my class Promise {
}
}

method start(Promise:U: &code, :$scheduler = $*SCHEDULER) {
method start(Promise:U: &code, :&catch, :$scheduler = $*SCHEDULER) {
my $p = Promise.new(:$scheduler);
my $vow = $p.vow;
$scheduler.cue(
{ $vow.keep(code()) },
:catch(-> $ex { $vow.break($ex) }) );
:catch(-> $ex { catch($ex) if &catch; $vow.break($ex); }) );
$p
}

Expand Down Expand Up @@ -202,6 +202,6 @@ my class Promise {

# Schedules a piece of asynchronous work using the current scheduler, and
# returns a Promise that represents it.
sub start(&code) { Promise.start(&code) }
sub start(&code, :&catch) { Promise.start(&code, :&catch) }

# vim: ft=perl6 expandtab sw=4

0 comments on commit f5d0bc2

Please sign in to comment.