Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/franciscotln/callbag-rescue
Callbag operator that rescues a failed source
https://github.com/franciscotln/callbag-rescue
Last synced: 18 days ago
JSON representation
Callbag operator that rescues a failed source
- Host: GitHub
- URL: https://github.com/franciscotln/callbag-rescue
- Owner: franciscotln
- License: mit
- Created: 2018-03-18T18:11:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-17T16:53:35.000Z (over 5 years ago)
- Last Synced: 2024-09-14T15:48:24.769Z (about 2 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - rescue
README
# callbag-rescue
Callbag higher-order operator that rescues a failed source. Works on either pullable or listenable sources.
`npm install callbag-rescue`
## examples
### listenables
After a failed promise, rescue with a new Callbag source:
```js
const forEach = require('callbag-for-each');
const fromPromise = require('callbag-from-promise');
const of = require('callbag-of');
const map = require('callbag-map');
const pipe = require('callbag-pipe');
const rescue = require('callbag-rescue');pipe(
fromPromise(Promise.reject({ status: 404 })),
map(res => res.body),
rescue(err => of({ type: 'ERROR', payload: err })),
forEach(n => {
console.log(n); // { type: 'ERROR', payload: { status: 404 } }
})
);
```### pullables
After a source Callbag throws an error, rescue it:
```js
const forEach = require('callbag-for-each');
const fromIter = require('callbag-from-iter');
const map = require('callbag-map');
const of = require('callbag-of');
const pipe = require('callbag-pipe');pipe(
fromIter([1, 2]),
map(num => num.a.name),
rescue(err => of({ type: 'ERROR', payload: err.message })),
forEach(n => {
console.log(n); // { type: 'ERROR', payload: 'Cannot read property "name" of undefined' }
})
);
```