Skip to content

Instantly share code, notes, and snippets.

@webhacking
Created January 24, 2019 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webhacking/9f0149f7ba890eed844014f64190b56e to your computer and use it in GitHub Desktop.
Save webhacking/9f0149f7ba890eed844014f64190b56e to your computer and use it in GitHub Desktop.
AsyncSubject Example
import {AsyncSubject} from 'rxjs/internal/AsyncSubject';
let subject = new AsyncSubject;
let i = 0;
const handle = setInterval(() => {
subject.next(i);
if (++i > 3) {
subject.complete();
clearInterval(handle);
}
}, 500);
const subscription = subject.subscribe((x: number) => {
console.log(`Next: ${String(x)}`);
}, (error: Error) => {
console.log(`Error: ${error}`);
}, () => {
console.log('Completed');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment