https://github.com/erikras/callbag-pausable
⏯️ Callbag Pausable is a callbag that will convert any callbag stream into one that can be paused and resumed via data or talkback events.
https://github.com/erikras/callbag-pausable
callbag observable pausable pause reactive resume rxjs streams
Last synced: 12 months ago
JSON representation
⏯️ Callbag Pausable is a callbag that will convert any callbag stream into one that can be paused and resumed via data or talkback events.
- Host: GitHub
- URL: https://github.com/erikras/callbag-pausable
- Owner: erikras
- License: mit
- Created: 2018-05-04T13:01:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-10T17:14:15.000Z (over 6 years ago)
- Last Synced: 2025-03-25T06:41:41.717Z (about 1 year ago)
- Topics: callbag, observable, pausable, pause, reactive, resume, rxjs, streams
- Language: JavaScript
- Size: 203 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ⏯️ callbag-pausable
[](https://www.npmjs.com/package/callbag-pausable)
[](https://npm-stat.com/charts.html?package=callbag-pausable)
[](https://travis-ci.org/erikras/callbag-pausable)
[](https://codecov.io/gh/erikras/callbag-pausable)

[Callbag](https://github.com/callbag/callbag) operator that allows data and talkbacks to pass through it freely until it receives a data or talkback message of `PAUSE`, in which case it stops the downflow of data until it receives another data or talkback message of `RESUME`.
Think of it like a valve on a pipe.
## Usage
```js
import interval from 'callbag-interval'
import observe from 'callbag-observe'
import pipe from 'callbag-pipe'
import pausable, { PAUSE, RESUME } from 'callbag-pausable'
const source = pipe(interval(100), pausable)
setTimeout(() => {
console.log('PAUSING')
source(1, PAUSE)
}, 400)
setTimeout(() => {
console.log('RESUMING')
source(1, RESUME)
}, 1000)
observe(console.log)(source) // 0
// 1
// 2
// PAUSING
// RESUMING
// 9
// 10
// 11
// ...
```
Or, as a talkback to an existing callbag (assuming `callbag$` has `pausable` somewhere in its pipe):
```js
const sendTalkbackValue = (callbag$, value) => {
callbag$(0, (type, talkback) => {
if (type === 0) {
talkback(1, value) // send value
talkback(2) // terminate
}
})
}
const pause = callbag$ => sendTalkbackValue(callbag$, PAUSE)
const resume = callbag$ => sendTalkbackValue(callbag$, RESUME)
```