Class DelayOperator
Implements the Delay operator. Mirrors rxjs's delay.
public static class DelayOperator
- Inheritance
-
System.ObjectDelayOperator
Methods
Delay<T>(Observable<T>, TimeSpan, IScheduler?)
Time-shifts every value from source by due, preserving relative order.
public static Observable<T> Delay<T>(this Observable<T> source, TimeSpan due, IScheduler? scheduler = null)
Parameters
sourceObservable<T>The source observable to delay.
dueTimeSpanThe amount of time by which to shift each value (see remarks for burst behavior).
schedulerISchedulerThe scheduler used to run the delay timer. Defaults to Instance when null.
Returns
- Observable<T>
An observable that emits the same values as
source, each shifted later in time by roughlydue, followed by the same completion or (immediate) error notification.
Type Parameters
TThe type of the values being delayed.
Remarks
Deliberately NOT built on DelayWhen/MergeMap: those subscribe to one independent timer per
value concurrently, and real timers (backed by the thread pool) don't guarantee same-duration timers
fire back in the order they were scheduled — which silently breaks the ordering guarantee this operator's
own documentation (and rxjs's) promises. Instead, this serializes emission through a single queue: only
one timer is ever active, always for the queue head, so firing order always matches arrival order
regardless of scheduler jitter.
Known simplification: for a burst of synchronous values, each one's delay is measured from when
its predecessor fired rather than from its own arrival, so latencies stack (item N fires at roughly
N × due) instead of each value landing at a uniform offset from when it arrived.
Correct for the common "space out slower-than-due emissions" case; revisit if a real use case needs
precise per-item latency under bursts (that's what the full scheduler/timer-queue work in M4 is for).
Errors are not queued: an error from source is forwarded immediately, without waiting
for any already-queued values to be flushed.