@@ -261,9 +261,57 @@ when the completion or otherwise of the tasks is more important to the
261
261
consumer than the actual results, or the results have been collected by
262
262
other means.
263
263
264
+
265
+ = head2 Supplies
266
+
267
+ A L < Supply > is an asynchronous data streaming mechanism that can be
268
+ consumed by one or more consumers simultaneously in a manner similar to
269
+ "events" in other programming languages and can be seem as enabling
270
+ "Event Driven" or reactive designs.
271
+
272
+ L < Supply > is a role that can be composed into your own types, but will
273
+ frequently be used as a "type punned" class to create standalone objects.
274
+
275
+ At its simplest a L < Supply > is a message stream that can have multiple
276
+ subscribers created with the method C < tap > on to which data items can be
277
+ placed with C < emit > :
278
+
279
+ my $supply = Supply.new();
280
+
281
+ $supply.tap( -> $v { say $v });
282
+
283
+ for 1 .. 10 {
284
+ $supply.emit($_);
285
+ }
286
+
287
+ The C < tap > method returns a L < Tap > object which can be used to obtain
288
+ information about the tap and also to turn it off when we are no lomger
289
+ interested in the events:
290
+
291
+ my $supply = Supply.new;
292
+ my $tap = $supply.tap(-> $v { say $v }, closing => {say "closing"});
293
+ $supply.emit("OK");
294
+ $tap.close; # Will trigger the closing callback
295
+ $supply.emit("Won't trigger the tap");
296
+
297
+ Calling C < close > on the L < Tap > object (or calling C < close > on the supply
298
+ object with the tap object as an argument,) will trigger the callback
299
+ specified by C < closing > if present and stop further events being sent to
300
+ the tap callback but otherwise leave the supply intact to receive further
301
+ events. Calling C < done > on the supply object will similarly call the
302
+ C < done > callback that may be specified for any taps but will not prevent any
303
+ further events being emitted to the stream, or taps receiving them.
304
+
264
305
= begin comment
265
306
266
- = head2 supplies
307
+ I couldn't think of a non-contrived but succinct example for a use-case
308
+
309
+ = end comment
310
+
311
+
312
+
313
+
314
+ = begin comment
267
315
268
316
= head3 tap
269
317
0 commit comments