Skip to content

Commit

Permalink
Adapt Promise.in example
Browse files Browse the repository at this point in the history
In the original version, the .kill method would be called on the Proc
after 5 seconds even if the other promise was successful.  This may not
be a problem in this case, but it implies that the other timeout promise
does not fire (when in fact, it will).
  • Loading branch information
lizmat committed Jul 6, 2018
1 parent e8f96f1 commit bc7070d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions doc/Type/Promise.pod6
Expand Up @@ -77,9 +77,14 @@ Creates a new Promise that will be kept in C<$seconds> seconds, or later.
my $proc = Proc::Async.new('perl6', '-e', 'sleep 10; warn "end"');
my $result = await Promise.anyof(
my $promise = $proc.start,
Promise.in(5).then: { note 'timeout'; $proc.kill }
).then: {$promise.result};
my $promise = $proc.start, # may or may not work in time
Promise.in(5).then: { # fires after 5 seconds no matter what
unless $promise { # don't do anything if we were successful
note 'timeout';
$proc.kill;
}
}
).then: { $promise.result }
# OUTPUT: «timeout␤»
C<$seconds> can be fractional or negative. Negative values are treated as
Expand Down

0 comments on commit bc7070d

Please sign in to comment.