Created
December 10, 2021 06:57
-
-
Save obaranovskyi/4a66044b840033173cc0bc0d3067a239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { firstValueFrom, Observable, Subject } from 'rxjs'; | |
async function demo<T>(observable: Observable<T>): Promise<void> { | |
const result = await firstValueFrom(observable); | |
console.log(result); | |
} | |
const subject = new Subject(); | |
const obs = subject.asObservable(); | |
demo(obs); | |
subject.next(1); | |
subject.next(2); | |
subject.next(3); | |
/* Observable is not completed yet, and will proceed to emit values */ | |
obs.subscribe(console.log); | |
subject.next(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment