ProtectedtransformStaticallAsyncResult version of Promise.all with fail-fast semantics.
Ok([...]) once all inputs resolve to Ok
(values preserved in input order).Err(e) as soon as the first input (in time, not array
order) resolves to Err, without waiting for the rest to settle.AsyncResult.merge for the variant that waits for every input
before picking the first Err by array order.
StaticfromCreate an AsyncResult from a Result, a PromiseLike, or a function returning a Result or a PromiseLike. Does not throw synchronously; rejections from the input promise propagate through the returned thenable.
An AsyncResult.
StaticmergeWaits for every input to settle as a Result, then returns the first
Err by array order (or Ok([...]) if none errored).
Unlike AsyncResult.all, an early Err does not short-circuit the
wait. Underlying promise rejections still reject via Promise.all
(rejections are not converted to Err values).
An array of AsyncResults to merge.
An AsyncResult that is either an array of all Ok values or the first Err value (by array order).
AsyncResult.all for fail-fast-on-Err semantics.
// ok
const asyncResult1 = AsyncResult.from(ok(1))
const asyncResult2 = AsyncResult.from(ok("2"))
const asyncResult3 = AsyncResult.from(ok(3n))
const merged = await AsyncResult.merge([asyncResult1, asyncResult2, asyncResult3])
expect(merged.unwrap()).toEqual([1, "2", 3n])
// err
const asyncResult1 = AsyncResult.from(ok(1))
const asyncResult2 = AsyncResult.from(err("2"))
const asyncResult3 = AsyncResult.from(err(3n))
const merged = await AsyncResult.merge([asyncResult1, asyncResult2, asyncResult3])
expect(merged.unwrapErr()).toBe("2")
Enables
yield* asyncResinside an asyncresult.gen/result.genAsyncbody: awaits the underlyingResult, then behaves like its sync counterpart — evaluates to theOkvalue or short-circuits the body with theErr. Equivalent toyield* (await asyncRes).