Constructor, which takes the promise to wrap.
The promise that was wrapped after attaching our custom logic.
Required to implement Promise
, but you almost certainly don't care about it.
All the same, it returns the string tag of the underlying promise.
Coerces the resolve value (which must be an Iterable
) into an array. The Iterable
requirement
comes from the Item<T>
return value: Item<T>
is equivalent to never
if T
is not an Iterable
.
Note that this function does NOT resolve the items within the array unless you pass the first argument
as true
. The items are not resolved sequentially unless you also pass a second argument as true
.
Cancel the FunPromise. A cancelled FunPromise will silently disregard any resolution or rejection which occurs after the cancellation.
Attaches a callback for only the rejection of the Promise. If the callback throws, then throws a [[NestedError
]] with
both the original rejection reason and the new thrown value.
The callback to execute when the Promise is rejected.
A Promise for the completion of the callback.
Waits for waitTimeMs
milliseconds before resolving. If returnValue
is provided, resolves with the provided value.
If waitTimeMs
is less than or equal to zero, then it simply defers until the call stack is clear.
Given a filtering function, apply the filtering function to each element of the promise's resolved value,
and return an array with the values for which the filtering function returns true
. If any of the filtering
results are rejected, the entire operation will be rejected.
The order of the elements in the result are stable with regard to the order of the elements in the promise's
resolved value. That is, if X < Y
and input[X]
and input[Y]
are both in the input, and input[X]
and
input[Y]
both pass the filtering function, then the output index of input[X]
will be less than the output
index of input[Y]
. However, the resolution order is not guaranteed: that is, input[Y]
may be resolved and
tested before input[X]
even though input[X]
has a lower output index than input[Y]
.
Executes the provided code whether the promise rejects or resolves.
Given an initial array of values and an accumulator function, apply the accumlator function to each element of the promise's resolved value, passing in the current array of values and the resolved item. Returns an array with the concatenated results of the accumulation. If any of the promise's values are rejected, the entire operation will be rejected.
The resolution order is not guaranteed. The accumulator function will be passed values as those values resolve.
Given a mapping function, apply the mapping function to each element of the promise's resolved value, and return an array with the concatenated results of the mapping. If any of the mapping results are rejected, the entire operation will be rejected.
The order of the elements in the result correspond to the order of the elements in the promise's resolved value. However, the resolution order is not guaranteed.
Given an initial value and an accumulator function, apply the accumlator function to each element of the promise's resolved value, passing in the current value and the result. Returns an array with the result of the accumulation. If any of the promise's values are rejected, the entire operation will be rejected.
The resolution order is not guaranteed. The accumulator function will be passed values as those values resolve.
Returns whether or not the promise has been cancelled. See cancel()
for more details.
Given a mapping function, apply the mapping function to each element of the promise's resolved value, and return an array with the results of the mapping. If any of the mapping results are rejected, the entire operation will be rejected.
The order of the elements in the result correspond to the order of the elements in the promise's resolved value. However, the resolution order is not guaranteed. For example, although the output at index 0 will hold the mapping of the input element at index 0, it is not guaranteed that the mapping of index 0 will be awaited before the mapping of index 1.
Takes a value (or a promise of a value) and returns a promise rejecting
with that value, after unwrapping as many layers of PromiseLike
wrappers as necessary. This disregards any existing status.
Takes a value (or a promise of a value) and resolves to the new value, disregarding any previous resolution value.
An alias for resolve
provided for compatibility with [the Bluebird API|http://bluebirdjs.com/docs/api/return.html].
Captures either fulfillment or rejection and resolves an object that describes the result.
Assuming that the resolved value is an iterable, then for each element of the array, captures either the fulfillment or rejection of that element.
Unwraps layers of PromiseLike
wrappers as necessary.
This behavior is actually part of the Promise/A+ spec, but the type system struggles with that fact, so this method is a workaround.
In a future version of this library, FunPromise
will extend Promise<Unpromise<T>>
instead of
just Promise<T>
, which will render this method irrelevant. Unfortunately, Typescript's type system
doesn't seem capable of handling that reality quite yet, so this is what we get.
For each element of the resolved iterable, unwraps layers of PromiseLike
wrappers as necessary.
Access the resolved value without changing it. Note that if the callback rejects (ie: throws), then the resulting promise will be rejected.
Access the rejection reason without changing it. Note that if the callback itself rejects (ie: throws),
both rejection reasons will be capture in a single [[NestedError
]].
Access each of the resolved values of a resolved iterable without changing it. Note that if the callback rejects (ie: throws), then the resulting promise will be rejected.
Attaches callbacks for the resolution and/or rejection of the Promise.
The optional callback to execute when the Promise is resolved.
A Promise for the completion of which ever callback is executed.
Handles rejections like 'catch', but wraps them in a [[NestedError
]] with the given message.
Resolves all the elements of the resolved value, which is assumed to be an Iterable
. If any
of the values reject, all the reasons are collected and wrapped in a [[NestedError
]].
Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.
An array of Promises.
A new Promise.
Given a PromisableIterable
whose values are nullary functions returning Promisable<T>
,
this executes all the functions simultaneously and returns the first whose return value passes the provided test.
The default test returns true if the value is not null
or undefined
.
If no function resolves successfully, the last seen rejection is thrown. If some functions resolve but some reject, and none of the resolved values pass the test, then the last seen rejection is thrown.
If all the functions resolve but to a value but no value passes the test, then this rejects with an error saying as much.
Waits for waitTimeMs
milliseconds before resolving. If returnValue
is provided, resolves with the provided value.
If waitTimeMs
is less than or equal to zero, then it simply defers until the call stack is clear.
Equivalent to FunPromise.resolve(items).filter(test)
.
Equivalent to FunPromise.resolve(values).flatFold(initialValue, accumulator)
.
Equivalent to FunPromise.resolve(values).flatMap(mapper)
.
Equivalent to FunPromise.resolve(values).fold(initialValue, accumulator)
.
Equivalent to FunPromise.resolve(values).map(mapper)
.
Takes a value (or a promise of a value) and returns a promise rejecting
with that value, after unwrapping as many layers of PromiseLike
wrappers as necessary.
Takes a value (or a promise of a value) and returns a promise wrapping it.
An alias for resolve
provided for consistency with the instance return
method.
Equivalent to FunPromise.resolve(iterable).settleAll()
.
Given a function (or a promise of a function) that returns a value (or a promise of a value), create a promise that executes the function and returns the value. If executing the function throws an exception, then that exception becomes the rejection of the promise.
Any arguments after the first will be passed into the function when it is invoked. If they are
a PromiseLike
, then they will be resolved and the resolution value will be passed into the
function instead.
This function is really useful in the following cases:
FunPromise
based on an async
functionFunPromise
based on a normal functionGenerated using TypeDoc
The class that you should use instead of
Promise
. It implements thePromise
API, so it should be a drop-in replacement.