Skip to content

๐Ÿ‘œ Like callbag-interval, but can be paused and resumed upon pulling

License

Notifications You must be signed in to change notification settings

staltz/callbag-pausable-interval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

callbag-pausable-interval

A callbag listenable source that sends incremental numbers every x milliseconds, but can be paused (and resumed) when it is pulled by a sink.

This is a hybrid source, it is both listenable and pullable. Don't use forEach directly as the sink for this source, because forEach pulls every time it receives data. You can use this source as the argument for sample, though.

npm install callbag-pausable-interval

example

const pausableInterval = require('callbag-pausable-interval')

const source = pausableInterval(600)

source(0, (type, data) => {
  if (type === 0) {
    const talkback = data
    // Every 2 seconds, send a message "null" back to the source
    setInterval(() => talkback(1, null), 2000)
  }
  if (type === 1) console.log(data)
})
// 0
// 1
// 2
// ...pauses and waits...
// 3
// 4
// 5
// ...pauses and waits...
// 6
// 7
// 8
// ...

About

๐Ÿ‘œ Like callbag-interval, but can be paused and resumed upon pulling

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published