Skip to content
PACKAGES

fromPromise()

Lift a Promise (or thenable) to a single-value stream: one DATA then COMPLETE, or ERROR on rejection. async pool (default pausable → a paused source buffers its late emit). Optional signal aborts to ERROR.

import { fromPromise } from "@graphrefly/ts/sources";
function fromPromise(
p: Promise<T> | PromiseLike<T>,
opts?: AsyncSourceOpts,
): Operator<never, T>
ParameterTypeDescription
pPromise<T> | PromiseLike<T>Promise or thenable to lift into the graph.
optsAsyncSourceOptsOptional abort signal and async source options.

A source operator that emits one DATA value and COMPLETE, or ERROR on rejection/abort.

import { graph } from "@graphrefly/ts/graph";
import { fromPromise } from "@graphrefly/ts/sources";
const user = graph().initNode(fromPromise(fetch("/user").then((res) => res.json())), []);

packages/ts/src/graph/sources.ts