Build a failed Future with the error data you provide.
Returns a Future
that'll complete when the first Future
of
the iterable you give will complete, with the value of that first
future. Be careful, completing doesn't necessarily mean completing
successfully!
Also see Future.firstSuccessfulOf
Returns a Future
that'll complete when the first Future
of
the iterable you give will complete successfully, with the value of that first
future.
Also see Future.firstCompletedOf
Applicative lifting for Future. Takes a function which operates on basic values, and turns it in a function that operates on futures of these values ('lifts' the function). The 2 is because it works on functions taking two parameters.
the first future type
the second future type
the new future type as returned by the combining function.
Applicative lifting for Future. 'p' stands for 'properties'.
Takes a function which operates on a simple JS object, and turns it in a function that operates on the same JS object type except which each field wrapped in a Future ('lifts' the function). It's an alternative to Future.liftA2 when the number of parameters is not two.
the object property type specifying the parameters for your function
the type returned by your function, returned wrapped in a future by liftAp.
Build a Future from an existing javascript Promise.
Build a Future from callback-style call. You get one callback to signal success, throw to signal failure.
Future.ofCallbackApi<string>(done => setTimeout(done, 10, "hello!"))
Build a successful Future with the value you provide.
Turns a list of futures in a future containing a list of items. Useful in many contexts.
But if a single future is failed, you get back a failed Future.
Also see Future.traverse
Takes a list, a function that can transform list elements to futures, then return a Future containing a list of the transformed elements.
But if a single element results in failure, the result also resolves to a failure.
Also see Future.sequence
Has no effect on a failed Future. If the Future was successful, will check whether its value matches the predicate you give as first parameter. If the value matches the predicate, an equivalent Future to the input one is returned.
If the value doesn't match predicate however, the second parameter function is used to compute the contents of a failed Future that'll be returned.
Transform the value contained in a successful Future. You return a
Future, but it is then "flattened" so we still return a Future
Transform the value contained in a successful Future. Has no effect if the Future was failed. Will turn a successful Future in a failed one if you throw an exception in the map callback (but please don't do it.. Rather use Future.filter or another mechanism).
This method is eager, will trigger the underlying Promise.
Transform the value contained in a failed Future. Has no effect if the Future was successful.
This method is eager, will trigger the underlying Promise.
Execute the side-effecting function you give if the Future is a failure.
Execute the side-effecting function you give if the Future is a success.
The then
call is not meant to be a part of the Future
API,
we need then so that await
works directly.
This method is eager, will trigger the underlying Promise.
Please rather use Future.map or Future.flatMap.
Get a Promise
from this Future
.
Transform this value to another value type. Enables fluent-style programming by chaining calls.
Generated using TypeDoc
A Future is the equivalent, and ultimately wraps, a javascript Promise. A fundamental difference is that Futures are lazy. Just defining a Future won't trigger its execution, you'll have to use it for that (call Future.map, Future.flatMap, use
await
on it and so on). This means that a Future can have one of the four states:That first state doesn't exist with Javascript Promises. In addition, while Futures support the Future.then call (so that among others you can use
await
on them), you should call Future.map and Future.flatMap.Futures represent an asynchronous computation. A Future will only ever be computed once at most. Once it's computed, calling Future.map or
await
will return instantly.