mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 23:16:30 +01:00
Documentation for Promise.timeout() and Promise.cancel()
This commit is contained in:
parent
d949074014
commit
f09d0cd93c
35
doc/api.txt
35
doc/api.txt
@ -205,6 +205,7 @@ emit anymore events.
|
||||
| Event | Parameters | Notes
|
||||
| +"success"+ | (depends) |
|
||||
| +"error"+ | (depends) |
|
||||
| +"cancel"+ | (depends) |
|
||||
|=========================================================
|
||||
|
||||
+promise.addCallback(listener)+ ::
|
||||
@ -213,6 +214,9 @@ Adds a listener for the +"success"+ event. Returns the same promise object.
|
||||
+promise.addErrback(listener)+ ::
|
||||
Adds a listener for the +"error"+ event. Returns the same promise object.
|
||||
|
||||
+promise.addCancelback(listener)+ ::
|
||||
Adds a listener for the +"cancel"+ event. Returns the same promise object.
|
||||
|
||||
+promise.emitSuccess(arg1, arg2, ...)+ ::
|
||||
If you created the promise (by doing +new node.Promise()+) then call
|
||||
+emitSuccess+ to emit the +"success"+ event with the given arguments.
|
||||
@ -223,6 +227,37 @@ the moment due to a bug; use +emitSuccess+ instead.)
|
||||
+promise.emitError(arg1, arg2, ...)+ ::
|
||||
Emits the +"error"+ event.
|
||||
|
||||
+promise.emitCancel(arg1, arg2, ...)+ ::
|
||||
Emits the +"cancel"+ event. You may still get a +"success"+ or +"error"+
|
||||
callback if the promise giver does not handle the cancel event. Use
|
||||
+promise.cancel()+ to ignore any later events.
|
||||
|
||||
+promise.cancel()+ ::
|
||||
Clears all +"success"+ and +"error"+ event listeners from the promise, then
|
||||
emits the +"cancel"+ event. Whether or not the promise is actually canceled
|
||||
or not depends on the promise giver.
|
||||
|
||||
+promise.timeout(timeout = undefined)+ ::
|
||||
If the +timeout+ parameter is provided, the promise will emit an +"error"+
|
||||
event after the given amount of millseconds. The timeout is canceled by any
|
||||
+"success"+, +"error"+ or +"cancel"+ event being emitted by the Promise.
|
||||
+
|
||||
To tell apart a timeout from a regular "error" event, use the following test:
|
||||
+
|
||||
----------------------------------------
|
||||
promise.addErrback(function(e) {
|
||||
if (e instanceof Error && e.message === 'timeout') {
|
||||
// handle timeout
|
||||
} else {
|
||||
// handle regular error
|
||||
}
|
||||
});
|
||||
----------------------------------------
|
||||
+
|
||||
If the +timeout+ parameter is not provided, the current timeout value, if any,
|
||||
is returned.
|
||||
+
|
||||
|
||||
+promise.wait()+ ::
|
||||
Blocks futher execution until the promise emits a success or error event.
|
||||
Events setup before the call to +promise.wait()+ was made may still be
|
||||
|
Loading…
Reference in New Issue
Block a user