@@ -158,28 +158,28 @@ dynamically scoped, this means that test scheduler modules can be developed
158
158
that poke a C<$*SCHEDULER> into C<EXPORT>, and then provide the test writer
159
159
with control over time.
160
160
161
- The simplest operation available on a scheduler is C<schedule>, which takes a
162
- C<Callable> object and schedules it.
161
+ The C<cue> method takes a C<Callable> object and schedules it.
163
162
164
- $*SCHEDULER.schedule( { say "Golly, I got scheduled!" });
163
+ $*SCHEDULER.cue: { say "Golly, I got scheduled!" }
165
164
166
- There is also a method to schedule an operation to run after a certain time
167
- period:
165
+ Various options may be supplied as named arguments. (All references to time
166
+ are taken to be in seconds, which may be fractional.) You may schedule an
167
+ event to fire off after some number of seconds:
168
168
169
- $*SCHEDULER.schedule-in( { say "10s later" }, 10);
169
+ $*SCHEDULER.cue: in=>10, { say "10s later" }
170
170
171
- And one to schedule an operation to run at a fixed interval, possibly with a
171
+ or at a given absolute time, specified as an C<Instant>:
172
+
173
+ $*SCHEDULER.cue: at=>$instant, { say "10s later" }
174
+
175
+ Use C<:every> to schedule an operation to run at a fixed interval, possibly with a
172
176
delay before the first scheduling.
173
177
174
178
# Every second, from now
175
- $*SCHEDULER.schedule-every({ say "Oh wow, a kangaroo!" }, 1);
176
- $*SCHEDULER.schedule-every({ say "Oh wow, a kangaroo!" }, 1, 0);
179
+ $*SCHEDULER.cue: :every(1), { say "Oh wow, a kangaroo!" }
177
180
178
181
# Every 0.5s, but don't start for 2s.
179
- $*SCHEDULER.schedule-every({ say "Kenya believe it?" }, 0.5, 2);
180
-
181
- [To consider: we could have a single schedule method taking named parameters
182
- :$catch, :$in, and :$every instead.]
182
+ $*SCHEDULER.cue({ say "Kenya believe it?" }, :every(0.5), :in(2));
183
183
184
184
If a scheduled item dies, the scheduler will catch this exception and pass it
185
185
to a C<handle_uncaught> method, a default implementation of which is provided
@@ -193,22 +193,28 @@ the entire application to terminate. However, it is possible to replace this:
193
193
For more fine-grained handling, it is possible to schedule code along with a
194
194
code object to be invoked with the thrown exception if it dies:
195
195
196
- $*SCHEDULER.schedule_with_catch(
196
+ $*SCHEDULER.cue:
197
197
{ upload_progress($stuff) },
198
- -> $ex { warn "Could not upload latest progress" });
198
+ catch => -> $ex { warn "Could not upload latest progress" }
199
+
200
+ Schedulers also provide counts of the number of operations in various states:
199
201
200
- Schedulers also provide a count of the number of outstanding operations to be
201
- performed:
202
+ say $*SCHEDULER.loads;
202
203
203
- say $*SCHEDULER.outstanding;
204
+ This returns, in order, the number of cues that are not yet runnable due to
205
+ delays, the number of cues that are runnable but not yet assigned to a thread,
206
+ and the number of cues that are now assigned to a thread (and presumably running).
207
+ [Conjecture: perhaps these should be separate methods.]
204
208
205
- They may optionally provide further introspection in order to support tools
209
+ Schedulers may optionally provide further introspection in order to support tools
206
210
such as debuggers.
207
211
208
212
There is also a C<CurrentThreadScheduler>, which always schedules things on
209
213
the current thread. It provides the same methods, just no concurrency, and
210
214
any exceptions are thrown immediately. This is mostly useful for forcing
211
- synchrony in places that default to asynchrony.
215
+ synchrony in places that default to asynchrony. (Note that C<.loads> can never
216
+ return anything but 0 for the currently running cues, since they're waiting
217
+ on the current thread to stop scheduling first!)
212
218
213
219
=head1 Promises
214
220
@@ -324,7 +330,7 @@ C<Promise.alarm> factory is implemented:
324
330
method alarm(Promise:U: $seconds, :$scheduler = $*SCHEDULER) {
325
331
my $p = Promise.new(:$scheduler);
326
332
my $k = $p.keeper;
327
- $scheduler.schedule-in( { $k.keep(True) }, $seconds);
333
+ $scheduler.cue: { $k.keep(True) }, :in( $seconds);
328
334
$p
329
335
}
330
336
0 commit comments