Created
March 10, 2017 10:33
-
-
Save allenevans/6a0a5b6e4b46fcea0e266bbf6ce59051 to your computer and use it in GitHub Desktop.
RxJS iterate over an array by time
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
const keyInputs = [ | |
['n', 1], | |
['e', 10], | |
['w', 100], | |
[' ', 1], | |
['y', 10], | |
['o', 100], | |
['r', 300], | |
['k', 200] | |
]; | |
Rx.Observable.from(keyInputs) | |
.concatMap(([key, delayFor]) => Rx.Observable.of(key).delay(delayFor)) | |
.subscribe(d => console.log(d)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
concatMap will emit each key in the sequence in order and delayed by the amount of time specified.