UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

19 lines (18 loc) 348 B
/** * Creates a ReadableStream the queues `x` and closes. * * @group Sources * @example * ``` * await of({ foo: 'bar' }).pipeTo(write(x => console.info(x))) * // { foo: 'bar' } * ``` */ export function of<T>(x: T) { return new ReadableStream<T>({ pull(controller) { controller.enqueue(x) controller.close() }, }) }