Skip to content

Commit 573df66

Browse files
committed
import operation timeout example
1 parent 7e850ef commit 573df66

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use v6;
2+
3+
=begin pod
4+
5+
=TITLE Timeout Operation
6+
7+
=AUTHOR stmuk
8+
9+
You want to timeout an operation (possibly long running)
10+
11+
=end pod
12+
13+
constant timeout = 3;
14+
15+
my $done = start {
16+
say "starting to sleep...";
17+
sleep 10; # long running operation here
18+
}
19+
20+
await Promise.anyof($done, Promise.in(timeout));
21+
22+
if $done {
23+
say "operation completed";
24+
}
25+
else {
26+
warn "timed out after {timeout} sec(s)";
27+
}
28+
29+
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)