politie / sherlock

A reactive programming library for JavaScript applications, built with TypeScript.
Apache License 2.0
39 stars 12 forks source link

Add Derivable#toPromise #59

Closed pavadeli closed 6 years ago

pavadeli commented 6 years ago

Comparable to Derivable#toObservable, but returns a Promise. 🙄 Very useful to wait until a certain condition is met, for example:

class Sample {
    value$ = atom(0);
    ready$ = atom(false);

    async valueWhenReady(): Promise<number> {
        await this.value$.toPromise({ when: this.ready$ });
    }
}