Skip to content

Instantly share code, notes, and snippets.

@allenevans
Created March 10, 2017 10:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save allenevans/6a0a5b6e4b46fcea0e266bbf6ce59051 to your computer and use it in GitHub Desktop.
Save allenevans/6a0a5b6e4b46fcea0e266bbf6ce59051 to your computer and use it in GitHub Desktop.
RxJS iterate over an array by time
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));
@allenevans
Copy link
Author

concatMap will emit each key in the sequence in order and delayed by the amount of time specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment