@writetome51/get-subscription-data
v2.0.0
Published
Returns data result from a Subscription to an Observable (or any Subscribable) once and then unsubscribes
Downloads
12
Maintainers
Readme
getSubscriptionData( subscribable: Subscribable<any>): Promise<any>
Async function that only returns the first data result of a Subscription
(to a Subscribable)
and then unsubscribes automatically. Useful if you only want the first result and don't
need to keep the Subscription open.
Examples
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
import {getSubscriptionData} from '@writetome51/get-subscription-data';