Skip to content

Commit 9c428a9

Browse files
committed
/.sleep/.alarm/
I think ".sleep" is confusing, as its functionality does not match sleep(). And from this, we could spec an alarm() function, which would just create a subscribable with an .alarm and code to be executed when the alarm arrives.
1 parent d8cd922 commit 9c428a9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

S17-concurrency.pod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ C<Exception>. Most of the time, however, the above is simply written as:
275275
Which is implemented by calling C<Promise.run>.
276276

277277
There is also a method to create a C<Promise> that is kept after a number of
278-
seconds:
278+
seconds, so it can act as an alarm:
279279

280-
my $kept_in_10s = Promise.sleep(10);
280+
my $kept_in_10s = Promise.alarm(10);
281281

282282
The C<result> is always C<True> and such a C<Promise> can never be broken. It
283283
is mostly useful for combining with other promises.
@@ -289,7 +289,7 @@ the resulting C<Promise> is also broken. The cause is passed along. When the
289289
C<Promise> is kept, it has a C<True> result.
290290

291291
my $calc = async { ... }
292-
my $timeout = Promise.sleep(10);
292+
my $timeout = Promise.alarm(10);
293293
my $timecalc = Promise.anyof($calc, $timeout);
294294

295295
There is also an C<allof> combinator, which creates a C<Promise> that will be
@@ -319,9 +319,9 @@ lifetime. Since C<keep> and C<break> on the C<Promise> itself just delegate
319319
to C<self.keeper.keep(...)> or C<self.keeper.break(...)>, obtaining the keeper
320320
before letting the C<Promise> escape to the outside world is a way to take
321321
ownership of the right to keep or break it. For example, here is how the
322-
C<Promise.sleep> factory is implemented:
322+
C<Promise.alarm> factory is implemented:
323323

324-
method sleep(Promise:U: $seconds, :$scheduler = $*SCHEDULER) {
324+
method alarm(Promise:U: $seconds, :$scheduler = $*SCHEDULER) {
325325
my $p = Promise.new(:$scheduler);
326326
my $k = $p.keeper;
327327
$scheduler.schedule-in({ $k.keep(True) }, $seconds);

0 commit comments

Comments
 (0)