Last active
September 21, 2015 21:59
-
-
Save mattpodwysocki/3aac1b730dbfe2a0ac5c to your computer and use it in GitHub Desktop.
How do I ensure that when someone throws from inside a subscribe call that it is honored and not swallowed by the Promise implementation? How do I break free from the jail?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FromPromiseObservable = (function(__super__) { | |
inherits(FromPromiseObservable, __super__); | |
function FromPromiseObservable(p) { | |
this.p = p; | |
__super__.call(this); | |
} | |
FromPromiseObservable.prototype.subscribeCore = function(o) { | |
this.p | |
.then(function (data) { | |
o.onNext(data); | |
o.onCompleted(); | |
}, function (err) { | |
o.onError(err); | |
}); | |
return disposableEmpty; | |
}; | |
return FromPromiseObservable; | |
}(ObservableBase)); | |
/** | |
* Converts a Promise to an Observable sequence | |
* @param {Promise} An ES6 Compliant promise. | |
* @returns {Observable} An Observable sequence which wraps the existing promise success and failure. | |
*/ | |
var observableFromPromise = Observable.fromPromise = function (promise) { | |
return new FromPromiseObservable(promise); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Rx = require('rx'); | |
var disp = Rx.Observable.fromPromise(Promise.resolve(42)) | |
.subscribe(function (x) { | |
// This somehow gets caught by Node.js and never seen | |
throw new Error(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment