This article needs a technical review. How you can help.
PromiseUtils.resolveOrTimeout offers a simple timeout mechanism for
Promise resolveOrTimeout( promise, delay, rejection );
Promise) The Promise that should resolve/reject quickly.
- (number) A delay after which to stop waiting for
promise, in milliseconds.
- (function) If
promisehasn't resolved/rejected after
delay, a value used to construct the rejection.
A promise that behaves as
promise is resolved/rejected within
delay ms, or rejects with
Following code assigns a promise which behaves as
myModule.shutdown(), but timed out after 1000 ms.
let p = PromiseUtils.resolveOrTimeout( myModule.shutdown(), 1000, () => new Error("The module took too long to shutdown") );
A new object, containing the new promise in the
promise property, and the methods to change its state in the
reject properties. See the
Deferred documentation for details.