1.0.0 • Published 4 years ago

ai-subject v1.0.0

Weekly downloads
1
License
MIT
Repository
gitlab
Last release
4 years ago

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.