rx-graceful

1.0.3 • Public • Published

rx-graceful rxjs logo

CircleCI

Makes RxJS Subjects graceful. Why? Because...

  • Exceptions usually terminate Subjects and often swallow errors.
  • It's naive to be confident our code does not contain an exception.

Installation

npm install rx-graceful

Example

'use strict'
 
const Rx = require('rxjs')
 
require('rx-graceful')(Rx)
 
const $ = new Rx.Subject()
 
$
  // (1) catches exceptions inside map
  .map(() => { throw Error() })
  // (2) catches rejections inside flatMap
  .flatMap(x => Promise.reject())
  // (3) catches exceptions inside async functions (as these are rejections as well)
  .flatMap(async x => { throw Error() })
  .subscribe(x => {
    // (4) catches exceptions inside the subscription handler
    throw Error()
  }, e => {
    // Handles errors (1), (2), (3), (4)
  })
 
$.next('some value')

Future improvements

  • Use lettable operators instead of mutating Subject.prototype, as soon as they're out of beta

Package Sidebar

Install

npm i rx-graceful

Weekly Downloads

2

Version

1.0.3

License

MIT

Last publish

Collaborators

  • gunar