Last active
July 21, 2016 19:03
-
-
Save Willmo36/9a7d5a76c1bea5391a88 to your computer and use it in GitHub Desktop.
RxJS stream from SuperAgent request
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
let Rx = require("rx"); | |
Rx.Observable.fromSuperagent = request => () => Rx.Observable.create(observer => { | |
request.end((err, res) => { | |
if (err) { | |
observer.onError(err) | |
} else { | |
observer.onNext(res); | |
} | |
observer.onCompleted(); | |
}) | |
}); |
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
Rx.Observable.fromSuperagent = function(req){ | |
return Rx.Observable.create(function(observable){ | |
req.end(function(err, res){ | |
if(err){ | |
observable.onError(err); | |
} else { | |
observable.onNext(res); | |
} | |
observable.onCompleted(); | |
}) | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example: