1.0.2 • Published 5 years ago

callbag-rescue v1.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

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:

 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:

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' }
  })
);
1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago