API reference › @evolu/common › Result › NextResult
type NextResult<A, E, D> = Result<A, E | Done<D>>;
Defined in: packages/common/src/Result.ts:768
A result for a pull-based protocol with three outcomes.
The consumer requests the next value (e.g. via next()), and the producer
responds with one of:
- An Ok containing
A— produced a value - An Err containing Done — completed normally with a done value
- An Err containing
E— failed with an error
Inspired by JavaScript's Iterator.next(), which returns { value, done }.
Example
import {
assertErr,
assertOk,
assertType,
done,
err,
ok,
type NextResult,
type Typed,
} from "@evolu/common";
const next = (index: number): NextResult<string, ReadFailedError, number> => {
if (index === 0) return ok("first");
if (index === 1) return err({ type: "ReadFailed" });
return err(done(index));
};
interface ReadFailedError extends Typed<"ReadFailed"> {}
const value = next(0);
assertType<NextResult<string, ReadFailedError, number>, typeof value>();
assertOk(value, "first");
assertErr(next(1), { type: "ReadFailed" });
assertErr(next(2), { type: "Done", done: 2 });