Last active
July 27, 2019 11:27
-
-
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
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
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