Skip to content

Instantly share code, notes, and snippets.

@webhacking
Created January 24, 2019 04:22
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/c5533c425a8f43db66b9ed37bda5caaf to your computer and use it in GitHub Desktop.
Save webhacking/c5533c425a8f43db66b9ed37bda5caaf to your computer and use it in GitHub Desktop.
Replay Subject Example
import {ReplaySubject} from 'rxjs/internal/ReplaySubject';
const subject = new ReplaySubject(2 /* buffer size */);
subject.next('a');
subject.next('b');
subject.next('c');
const subscription = subject.subscribe((x: string) => {
console.log(`Next: ${x}`);
}, (error: Error) => {
console.log(`Error: ${error}`);
}, () => {
console.log('Completed');
});
// => Next: b
// => Next: c
subject.next('d');
// => Next: d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment