We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7e850ef commit 573df66Copy full SHA for 573df66
categories/cookbook/16processes/16-01-operation-timeout.pl
@@ -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