repeat<T> static method
Emits the same value, count times, on the first pulse received
from source.
repeat emits the same value multiple times on the first trigger. This is useful for generating repeated signals.
When to use
Use repeat when you need to emit the same value multiple times.
- Heartbeats: Emitting multiple heartbeat signals.
- Retry Signals: Emitting multiple retry attempts.
- Test Data: Emitting repeated test values.
- Pulses: Generating multiple pulses.
- Acknowledgments: Sending multiple acknowledgment signals.
- Alerts: Emitting repeated alert signals.
How it works
- The first source pulse arms the instruction.
valueis emittedcounttimes.- Later pulses are ignored.
- Each emitted value gets the step
'Repeat'for provenance.
Parameters:
source: The Trigger Source. The cell that triggers the emission.value: The Value to Repeat. The value to emit multiple times.count: Number of Repetitions. How many times to emit the value. Defaults to 1.
Type Parameters:
T: The type of the value to repeat.
Returns:
A FlowHandle that can be used to observe the emitted values.
Example
final start = Cell.ingress<void>();
final handle = Flow.repeat<String>(
start.cell,
value: 'ping',
count: 3,
);
start.emit(null);
// Outputs: ping, ping, ping
See Also:
- of: For emitting fixed values.
- fromIterable: For emitting from an iterable.
- range: For emitting a numeric range.
Implementation
static FlowHandle repeat<T>(
Cell source, {
required T value,
int count = 1,
}) {
return Repeat<T>(value, count: count).toHandle(source: source);
}