Skip to content

Instantly share code, notes, and snippets.

@edulan
Last active April 19, 2018 15:32
Show Gist options
  • Save edulan/198ce1868ccd19ed7194c3b4d67dbd2b to your computer and use it in GitHub Desktop.
Save edulan/198ce1868ccd19ed7194c3b4d67dbd2b to your computer and use it in GitHub Desktop.
Rx photobooth, take 4 photos with a 5 seconds countdown between them
const takePhoto = () => new Promise((resolve) => (setTimeout(resolve, Math.random() * 1E3 + 5E2, 'photo')))
const makeCountdown = (seconds) =>
Rx.Observable
.concat(
Rx.Observable
.interval(1E3)
.take(seconds),
Rx.Observable.defer(() => takePhoto())
)
Rx.Observable
.range(1, 4)
.concatMap(() => makeCountdown(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment