Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/writetome51/get-subscription-data

Async function that returns the data result of a Subscription (to a Subscribable) only once and then unsubscribes.
https://github.com/writetome51/get-subscription-data

rxjs-observable rxjs-subscriptions unsubscribe

Last synced: 1 day ago
JSON representation

Async function that returns the data result of a Subscription (to a Subscribable) only once and then unsubscribes.

Awesome Lists containing this project

README

        

# getSubscriptionData(
      subscribable: Subscribable<any>
): Promise<any>

Async function that only returns the first data result of a [Subscription](https://rxjs-dev.firebaseapp.com/api/index/class/Subscription)
(to a [Subscribable](https://rxjs-dev.firebaseapp.com/api/index/interface/Subscribable))
and then unsubscribes automatically. Useful if you only want the first result and don't
need to keep the Subscription open.

## Examples
```js
async function logToConsole() {
let data = await getSubscriptionData(
sendHTTPRequest('http://website.com') // returns an observable
);
console.log(data);
}

async function getFirstLottoNumber() {
return await getSubscriptionData(lottoNumbersObservable);
}
```

## Installation
`npm i @writetome51/get-subscription-data`

## Loading
```js
import {getSubscriptionData} from '@writetome51/get-subscription-data';
```