-
Notifications
You must be signed in to change notification settings - Fork 8
throttle
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>
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.
xs = source
ys = output
xs ──o──o──o──o─────────────o─o─/
│ │
│ dueTimeMs │
└-----------┐ └-┐
│ │
ys ───────────────────────o─────o/
Unless specified, this operator uses Scheduler.synchronous
to determine time
IObservable.<T>
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