Skip to content
richardszalay edited this page May 20, 2011 · 7 revisions

Emits the latest value on a time interval from a source sequence

function sample(dueTimeMs : uint, 
    scheduler : IScheduler = null) : IObservable.<sourceValueClass>

Remarks

The last value in every dueTimeMs milliseconds window will be emitted. If no value was emitted in that time period, the sequence will not emit a value and the next interval will begin.

If the source sequence completes, the sequence will complete after emitting a value at the next dueTimeMs interval. If the source sequence errors, the sequence will complete immediately.

The returned sequence completes when the source sequence completes.

The returned sequence errors when the source sequences errors.

Marble Diagrams

xs = source
ys = output

xs  ──o──o──o──o────oo─o───/
               └──┐    └──────┐
        dueTimeMs │ dueTimeMs │
       -----------│-----------│
                  │           │
ys  ──────────────o───────────o/

xs  ──o──o──o──o────oo─o───x
               └──┐        │
        dueTimeMs │ dueTimeMs
       -----------│--------│
                  │        │
ys  ──────────────o────────x

h3. Scheduling

Unless specified, this operator uses @Scheduler.synchronous@ to schedule the interval.

h3. Return Value

@IObservable.<sourceValueClass>@

h2. Examples

```as3
var source : IObservable = Observable.interval(500)
    .sample(1000);

source.subscribe(function(value : int) : void
    {
        trace(value);
    });

// Trace output is:
// 1 (at 1000ms from start)
// 3 (at 2000ms from start)
// 5 (at 3000ms from start)
Clone this wiki locally