@@ -343,15 +343,127 @@ Creates a "rotoring" supply with the same semantics as List.rotor.
343
343
Creates a new supply in which all values flowing through the given supply
344
344
are emitted, but with the given delay in seconds.
345
345
346
- = head2 throttle
346
+ = head2 method throttle
347
347
348
- method throttle(Supply:D: $elems, $seconds, $delay = 0, :$scheduler) returns Supply:D
348
+ method throttle(Supply:D:
349
+ $limit, # values / time or simultaneous processing
350
+ $seconds or $callable, # time-unit / code to process simultaneously
351
+ $delay = 0, # initial delay before starting, in seconds
352
+ :$control, # supply to emit control messages on (optional)
353
+ :$status, # supply to tap status messages from (optional)
354
+ :$bleed, # supply to bleed messages to (optional)
355
+ :$vent-at, # bleed when so many buffered (optional)
356
+ :$scheduler, # scheduler to use, default $*SCHEDULER
357
+ ) returns Supply:D
349
358
350
- Produces a C < Supply > that throttles emitting the values of the given Supply
351
- on the created C < Supply > by the number of elements (specified by the first
352
- parameter) per number of seconds (specified by the second parameter).
353
- Optionally allows for specification of delay (in number of seconds), and
354
- scheduler to be used (defaults to $*SCHEDULER).
359
+ Produces a C < Supply > from a given Supply, but makes sure the number of
360
+ messages passed through, is limited.
361
+
362
+ It has two modes of operation: per time-unit or by maximum number of
363
+ execution of a block of code: this is determined by the second positional
364
+ parameter.
365
+
366
+ The first positional parameter specifies the limit that should be applied.
367
+
368
+ If the second positional parameter is a C < Callable > , then the limit indicates
369
+ the maximum number of parallel processes executing the Callable, which is
370
+ given the value that was received. The emitted values in this case will be
371
+ the C < Promise > s that were obtained from C < start > ing the Callable.
372
+
373
+ If the second positional parameter is a numeric value, it is interpreted as
374
+ the time-unit (in seconds). If you specify B < .1 > as the value, then it makes
375
+ sure you don't exceed the limit for every tenth of a second.
376
+
377
+ If the limit is exceeded, then incoming messages are buffered until there
378
+ is room to pass on / execute the Callable again.
379
+
380
+ The third positional parameter is optional: it indicates the number of
381
+ seconds the throttle will wait before passing on any values.
382
+
383
+ The :control named parameter optionally specifies a Supply that you can
384
+ use to control the throttle while it is in operation. Messages that
385
+ can be sent, are strings in the form of "key:value". Please see below
386
+ for the types of messages that you can send to control the throttle.
387
+
388
+ The :status named parameter optionally specifies a Supply that will receive
389
+ any status messages. If specified, it will at least send one status message
390
+ after the original Supply is exhausted. The status message is a hash with
391
+ the following keys:
392
+
393
+ = over 2
394
+
395
+ = item allowed
396
+
397
+ The current number of messages / callables that is still allowed to be
398
+ passed / executed.
399
+
400
+ = item bled
401
+
402
+ The number of messages routed to the :bleed Supply.
403
+
404
+ = item buffered
405
+
406
+ The number of messages currently buffered because of overflow.
407
+
408
+ = item emitted
409
+
410
+ The number of messages emitted (passed through).
411
+
412
+ = item id
413
+
414
+ The id of this status message (a monotonically increasing number). Handy
415
+ if you want to log status messages.
416
+
417
+ = item limit
418
+
419
+ The current limit that is being applied.
420
+
421
+ = item vent-at
422
+
423
+ The maximum number of messages that may be buffered before they're
424
+ automatically re-routed to the :bleed Supply.
425
+
426
+ =back
427
+
428
+ The :bleed named parameter optionally specifies a Supply that will receive
429
+ any values that were either explicitly bled (with the B < bleed > control
430
+ message), or automatically bled (if there's a B < vent-at > active).
431
+
432
+ The :vent-at named parameter indicates the number of values that may be
433
+ buffered before any additional value will be routed to the :bleed Supply.
434
+ Defaults to 0 if not specified (causing no automatic bleeding to happen).
435
+ Only makes sense if a :bleed Supply has also been specified.
436
+
437
+ The :scheduler named parameter indicates the scheduler to be used. Defaults
438
+ to $*SCHEDULER.
439
+
440
+ = head3 control messages
441
+
442
+ These messages can be sent to the :control Supply. A control message
443
+ consists of a string of the form "key: value", e.g. "limit: 4".
444
+
445
+ = over 2
446
+
447
+ = item limit
448
+
449
+ Change the number of messages (as initially given in the first positional)
450
+ to the value given.
451
+
452
+ = item bleed
453
+
454
+ Route the given number of buffered messages to the :bleed Supply.
455
+
456
+ = item vent-at
457
+
458
+ Change the maximum number of buffered values before automatic bleeding
459
+ takes place. If the value is lower than before, will cause immediate
460
+ rerouting of buffered values to match the new maximum.
461
+
462
+ = item status
463
+
464
+ Send a status message to the :status Supply with the given id.
465
+
466
+ =back
355
467
356
468
= head2 method stable
357
469
@@ -472,7 +584,7 @@ supplies are done. Can also be called as a class method.
472
584
473
585
= head2 method zip-latest
474
586
475
- method zip(Supply @*supplies, :&with = &[,], :$initial) returns Supply:D
587
+ method zip-latest (Supply @*supplies, :&with = &[,], :$initial) returns Supply:D
476
588
477
589
Creates a supply that emits combined values as soon as there is a new value
478
590
seen on B < any > of the supplies. By default, C < Lists|/type/List > are
0 commit comments