Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/writetome51/get-subscription-data
- Owner: writetome51
- License: mit
- Created: 2019-10-21T00:50:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-06T22:14:26.000Z (over 4 years ago)
- Last Synced: 2024-12-20T08:36:13.462Z (14 days ago)
- Topics: rxjs-observable, rxjs-subscriptions, unsubscribe
- Language: TypeScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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';
```