ai-subject
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

ai-subject

npm Gitlab pipeline status

Send values to an async iterable like Reactive Extensions does. This multicasts values to be multicasted to many listeners. The listener would be anything that retrieves an iterator via the [Symbol.asyncIterator]() method. Subjects are like EventEmitters.

Usage

import { AiSubject } from "ai-subject"

const aiSubject = new AiSubject()

Creates a new instance of AiSubject.

aiSubject[Symbol.asyncIterator]()

Listens to the subject until it finishes.

Returns:

  • AsyncIterable & AsyncIterator - An iterator that listens to values sent to the subject.

Note: The subject will only emit values sent via onNext if the iterator is listened to.

aiSubject.onNext(value)

Sends a new value to all of the subject's listeners.

Parameters:

  • value - The value

aiSubject.onEnd()

Ends the subject.

aiSubject.onError(error)

Transitions the subject to an error state.

Parameters:

  • error - The error.

Package Sidebar

Install

npm i ai-subject

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

11.1 kB

Total Files

11

Last publish

Collaborators

  • seangenabe