Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save obaranovskyi/4a66044b840033173cc0bc0d3067a239 to your computer and use it in GitHub Desktop.
Save obaranovskyi/4a66044b840033173cc0bc0d3067a239 to your computer and use it in GitHub Desktop.
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