fromAny()
Normalizes any value type into a callbag ProducerStore that emits value(s) then completes.
Supported inputs (checked in order):
- Promise / PromiseLike — emits resolved value, errors on reject
- Observable (
{ subscribe }) — bridges next/error/complete - AsyncIterable — pulls values, aborts on cleanup
- Iterable (excluding strings) — emits each element synchronously
- Plain value — emits once, completes
Signature
ts
function fromAny<T>(
input: T | Promise<T> | Iterable<T> | AsyncIterable<T>,
): ProducerStore<T>Parameters
| Parameter | Type | Description |
|---|---|---|
input | `T | Promise<T> |
Returns
ProducerStore<T>
Basic Usage
ts
import { fromAny } from 'callbag-recharge/extra';
fromAny(42); // emits 42
fromAny(fetch('/api').then(r => r.json())); // emits response
fromAny([1, 2, 3]); // emits 1, 2, 3
fromAny(asyncGenerator()); // emits each yielded value
fromAny(rxjsObservable$); // bridges observable