Skip to content

Instantly share code, notes, and snippets.

@wolfflow
Created February 14, 2014 11:07
Show Gist options
  • Save wolfflow/8999346 to your computer and use it in GitHub Desktop.
Save wolfflow/8999346 to your computer and use it in GitHub Desktop.
Bacon.repeatedlyOnFrame -- rAF based implementation of Bacon.repeatedly
# divisor adjusts sequence rate, e.g. value of 2 means that new values are produced on even frames only
# Thus Bacon.repeatedlyOnFrame(values, 6) is barely equivalent to 100ms timeout at 60fps
Bacon.repeatedlyOnFrame = (values, divisor = 1) ->
index = 0
Bacon.scheduleAnimFrame()
.scan 0, -> it + 1
.filter (tick) -> !(tick % divisor)
.map (tick) ->
values[index++ % values.length]
.toEventStream()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment