Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staltz/callbag-pausable-interval
👜 Like callbag-interval, but can be paused and resumed upon pulling
https://github.com/staltz/callbag-pausable-interval
Last synced: 28 days ago
JSON representation
👜 Like callbag-interval, but can be paused and resumed upon pulling
- Host: GitHub
- URL: https://github.com/staltz/callbag-pausable-interval
- Owner: staltz
- License: mit
- Created: 2018-03-04T22:42:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-04T22:44:25.000Z (over 6 years ago)
- Last Synced: 2024-10-09T09:47:24.450Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - pausable-interval
README
# 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
```js
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
// ...
```