(require("promise-nodeify"))(promisenon-null, callbackopt, nullable) → {Promise.<ValueType>|undefined}
Calls a node-style callback when a Promise is resolved or rejected.
This function provides the behavior of
then
nodeify
,
when.js node.bindCallback
,
or bluebird Promise.prototype.nodeify
(now
Promise.prototype.asCallback
) (without options).
@ template ValueType
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
promise |
Promise.<ValueType> | Promise to monitor. | |
callback |
function |
<optional> <nullable> |
Node-style callback to be
called when promise is resolved or rejected. If
promise is rejected with a falsey value the first argument
will be an instance of Error with a .cause
property with the rejected value. |
Returns:
undefined
if
callback
is a function, otherwise a Promise
which behaves like promise
(currently is promise
,
but is not guaranteed to remain so).
- Type
- Promise.<ValueType> | undefined
Methods
(static) delegated(promisenon-null, callbackopt, nullable) → {Promise.<ValueType>|undefined}
A version of promiseNodeify which delegates to the
.nodeify
method on promise
, if present.
This may be more performant than {@see promiseNodeify} and have additional
implementation-specific features, but the behavior may differ from
promiseNodeify
and between Promise implementations.
Note that this function only passes the callback argument to
.nodeify
, since additional arguments are interpreted
differently by different libraries (e.g. bluebird treats the next argument
as an options object while then treats it as this
for the
callback).
@ template ValueType
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
promise |
Promise.<ValueType> | Promise to monitor. | |
callback |
function |
<optional> <nullable> |
Node-style callback. |
Returns:
Value returned by
.nodeify
. Known implementations return the
promise
argument when callback is falsey and either
promise
or undefined
otherwise.
- Type
- Promise.<ValueType> | undefined
(static) nodeifyThis(callbackopt, nullable) → {Promise.<ValueType>|undefined}
Polyfill for
Promise.prototype.nodeify
which behaves like
promiseNodeify.
@ template ValueType
This:
- {!Promise.<ValueType>}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
function |
<optional> <nullable> |
Node-style callback. |
Returns:
undefined
if
callback
is a function, otherwise a Promise
which behaves like promise
(currently is promise
,
but is not guaranteed to remain so).
- Type
- Promise.<ValueType> | undefined