method in
Documentation for method in assembled from the following types:
class Promise
From Promise
(Promise) method in
method in(Promise:U: $seconds, :$scheduler = $*SCHEDULER --> Promise:D)
Creates a new Promise that will be kept in $seconds seconds, or later.
my $proc = Proc::Async.new('perl6', '-e', 'sleep 10; warn "end"');
my $result = await Promise.anyof(
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»
$seconds can be fractional or negative. Negative values are treated as 0 (i.e. keeping the returned Promise right away).
Please note that situations like these are often more clearly handled with a react and whenever block.