Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Created May 26, 2015 16:00
Show Gist options
  • Save Willmo36/9e5c07141a012cd271b6 to your computer and use it in GitHub Desktop.
Save Willmo36/9e5c07141a012cd271b6 to your computer and use it in GitHub Desktop.
RxJS to$q for angular 1.2.XXX
rx.Observable.prototype.to$q = function(onFulfiled, onRejected) {
var source = this;
var deferred = $q.defer();
var value, hasValue = true;
source.subscribe(function(v) {
value = v;
hasValue = true;
}, deferred.reject, function () {
hasValue && deferred.resolve(value);
});
return deferred.promise.then(onFulfiled, onRejected);
};
@Willmo36
Copy link
Author

When using angular 1.2.xxx, you are stuck with the deferred based $q.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment