forked from richardszalay/raix
-
Notifications
You must be signed in to change notification settings - Fork 0
timeout
richardszalay edited this page May 20, 2011
·
13 revisions
Emits an error, canceling the sequence, after a period of inactivity.
function timeout(timeoutMs:uint, other:IObservable.<T> = null,
scheduler:IScheduler=null) : IObservable.<T>
Where source is the observable sequence to subscribe to when a timeout occurs
After timeoutMs milliseconds of inactivity from the source sequence (ie. no onNext values), an raix.reactive.TimeoutError will be raised. If other is specified, that sequence will be subscribed to after the timeout instead of raising an error.
The returned sequence completes when the source sequence completes.
The returned sequence errors if the source sequence errors, if source is not specified and a timeout occurs, or if source is specified and raises an error after a timeout occurs.
xs ──o─────o─────────────┐
│ │ timeout │
│ │-------------│
ys ──o─────o─────────────x
xs ──o─────o────/
│ │ │
│ │ │
ys ──o─────o────/
xs ──o─────o─────────────┐
│ │ │
other │ │ timeout └─o─o─/
│ │------------- │ │ │
ys ──o─────o───────────────o─o─/
Unless specified, Scheduler.synchronous
will be used to schedule the timeout
IObservable.<T>
// Timeout a urlLoader with the default error
Observable.urlLoader(new URLRequest("http://www.github.com"))
.timeout(5000)
.subscribe(
function(data : Object) : void { trace(x); },
function() : void { trace("Completed"); },
function(e:Error) : void { trace("Error: " + e.message); }
);
// Trace output is:
// (After 1 second, if the request times out)
// Error: Sequence timed out
// Timeout with a custom sequence to use instead
Observable.never()
.timeout(1000, toObservable([1, 2, 3]))
.subscribe(
function(x:int) : void { trace(x); },
function() : void { trace("Completed"); },
function(e:Error) : void { trace("Error: " + e.message); }
);
// Trace output is:
// (After 1 second)
// 1
// 2
// 3
// Completed