omisabledeprecated

Omisable - Both a Promise or an Observable, creating a single object that is both Promise-like and Observable-like

Usage no npm install needed!

<script type="module">
  import omisable from 'https://cdn.skypack.dev/omisable';
</script>

README

omisable

Omisable - Both a Promise or an Observable, creating a single object that is both Promise-like and Observable-like

omisable provides a hybrid class that is both a Promise and an Observable to allow consumers how to interact with your api. The Omisable class defers creation of both the Observable and Promise until they are needed.

The factory for the Observable, and optionally the Promise, allows the producer to determine if the object should be a shared instance, or a single-use object.

Getting started

In your node root, run:

npm install --save omisable

Minimal usage example:

it('should resolve', async function () {
    const factory = () => Observable.from(['result']);
    const omp = new Omisable<string>(factory);
    const result = await omp;
    assert(result === 'result');
});

It is often more efficient to provide a Promise factory as well and is one of the driving reasons this class was created. If no Promise factory is provide, as above, then it behaves similar to Rx.Observable.from(source).take(1).asPromise().

More Information

License

MIT Licence Copyright (c) 2018