Skip to content

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

License

Notifications You must be signed in to change notification settings

writetome51/get-subscription-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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';

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published