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 { Observable, Subscriber } from 'rxjs'; | |
const obs = new Observable((subscriber: Subscriber<number>) => { | |
subscriber.next(1); | |
subscriber.complete(); | |
}); | |
obs.subscribe(console.log); |
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(); |
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 { EmptyError, firstValueFrom, Observable, Subject } from 'rxjs'; | |
async function demo<T>(observable: Observable<T>): Promise<void> { | |
try { | |
const result = await firstValueFrom(observable); | |
console.log(result); | |
} catch (error) { | |
console.log(error instanceof EmptyError); | |
console.error(error); |
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> { | |
try { | |
const result = await firstValueFrom(observable, { defaultValue: 25 }); | |
console.log(result); | |
} catch (error) { | |
console.error(error); | |
} |
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 { lastValueFrom, Observable, Subject } from 'rxjs'; | |
async function demo<T>(observable: Observable<T>): Promise<void> { | |
const result = await lastValueFrom(observable); | |
console.log(result); | |
} | |
const subject = new Subject(); | |
demo(subject.asObservable()); |
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 { EmptyError, lastValueFrom, Observable, Subject } from 'rxjs'; | |
async function demo<T>(observable: Observable<T>): Promise<void> { | |
try { | |
const promiseResult = await lastValueFrom(observable); | |
console.log(promiseResult); | |
} catch (error) { | |
console.log(error instanceof EmptyError); | |
console.error(error); |
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 { EmptyError, lastValueFrom, Observable, Subject } from 'rxjs'; | |
async function demo<T>(observable: Observable<T>): Promise<void> { | |
try { | |
const promiseResult = await lastValueFrom(observable, { defaultValue: 25 }); | |
console.log(promiseResult); | |
} catch (error) { | |
console.log(error instanceof EmptyError); | |
console.error(error); |
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 { from } from 'rxjs'; | |
from(Promise.resolve(2)) | |
.subscribe({ | |
next: console.log, | |
error: console.error, | |
complete: () => console.log(`complete`) | |
}); |
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 { | |
combineLatest, | |
of, | |
merge, | |
concat, | |
exhaustMap, | |
mergeMap, | |
concatMap, | |
forkJoin, | |
} from 'rxjs'; |
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 { from } from 'rxjs'; | |
const fromPromise$ = from( | |
new Promise((resolve, reject) => { | |
console.log('Will be invoked only once, and right away.') | |
resolve(3); | |
}) | |
); |
OlderNewer