prelude

@prelude/channel · v2.0.1

SourceAPI referenceChangelognpm

Channel module

Usage

npm i -E @prelude/channel
import * as Ch from '@prelude/channel'

Reading and completion

When a channel can contain undefined, maybeRead() cannot distinguish a queued undefined value from completion because both produce undefined. Use next() and inspect its done property when that distinction matters.

Failure

Cancellation

read, maybeRead, write, maybeWrite and writeIgnore take { signal }; select, selectNext and selectAsync take { signal } as their first argument; after, ofIterable and ofAsyncIterable take it in a trailing options object.

const controller = new AbortController()
const value = await ch.read({ signal: controller.signal })
for await (const value of Ch.select({ signal: controller.signal }, a, b)) { ... }

Closing a channel (close, closeWriting, breaking out of for await) remains the way to stop all readers and writers.

License

This package is dedicated to the public domain under CC0 1.0.