Created
April 30, 2020 16:37
-
-
Save zapkub/73f34f67ac3734413965b0b07dbc9454 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { BehaviorSubject, Subject, Observable, of, interval } from 'rxjs'; | |
import { delay, map, take, tap, timeout } from 'rxjs/operators'; | |
function PostLogin(): Observable<number> { | |
return interval(1000).pipe(take(1), map(() => 200)); | |
} | |
class LoginService { | |
public async performLogin() { | |
console.log('BOF1'); | |
const result = await this.performLogin$().pipe(timeout(5000)).toPromise(); | |
console.log('done!'); | |
console.log('EOF1'); | |
} | |
public performLoginSubscribe() { | |
console.log('BOF2'); | |
this.performLogin$().subscribe(() => { | |
console.log('done!') | |
console.log('EOF2') | |
}); | |
} | |
private performLogin$(): Observable<{ code: number }> { | |
return PostLogin().pipe( | |
map(code => ({ code })), | |
); | |
} | |
} | |
async function start() { | |
const loginService = new LoginService(); | |
await loginService.performLogin() | |
console.log('End of main') | |
} | |
start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment