Skip to content

Instantly share code, notes, and snippets.

@emilio2hd
Last active July 27, 2019 11:27
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 emilio2hd/ebfa46553a4092679121a7254a748bde to your computer and use it in GitHub Desktop.
Save emilio2hd/ebfa46553a4092679121a7254a748bde to your computer and use it in GitHub Desktop.
Print message array every 5000 ms or if the buffer reach 5 items
export class AppComponent implements OnInit {
messageBuffer$ = new Subject<string>();
msgCount = 0;
ngOnInit(): void {
this.messageBuffer$.pipe(
bufferTime(5000, null, 5),
filter(buffer => buffer.length > 0),
).subscribe(console.log);
}
sendSomeMessage() {
this.messageBuffer.next(`Message ${++this.msgCount}`)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment