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

Ignores values that are followed by another value within a set period of time.

function throttle(dueTimeMs : uint, 
    scheduler : IScheduler = null) : IObservable.<T>

Remarks

When no extra values are emitted for dueTimeMs, the latest value is emitted. A simple example is textbox autocomplete, where results should only be queries after a few hundred milliseconds of inactivity.

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─────────────o─o─/
               │               │ 
               │ dueTimeMs     │ 
               └-----------┐   └-┐
                           │     │
ys  ───────────────────────o─────o/

Scheduling

Unless specified, this operator uses Scheduler.synchronous to determine time

Return Value

IObservable.<T>

Examples

var source : IObservable = Observable.fromEvent(textBox, Event.CHANGED)
    .throttle(500)
    .map(function(e:Event):String
    {
        return textBox.text;
    });

source.subscribe(function(text : String) : void
    {
        trace(text);
    });

// Trace output is text of textbox after 500ms of inactivity
Clone this wiki locally