Created
October 2, 2015 03:36
-
-
Save AtsushiSuzuki/f52685142204e39ad149 to your computer and use it in GitHub Desktop.
Rxjsでasync.series相当の処理を行う。
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
const Rx = require('rx'); | |
Rx.Observable.prototype.mapParallel = function (fn) { | |
return this.concatMap((v) => Rx.Observable.fromNodeCallback(fn)(v)); | |
}; | |
Rx.Observable.prototype.mapSeries = function (fn) { | |
return this.concatMap((v) => Rx.Observable.defer(() => Rx.Observable.fromNodeCallback(fn)(v))); | |
}; | |
Rx.Observable.of(1, 2, 3, 4) | |
.mapSeries((v, done) => setTimeout(() => done(null, v), 100)) | |
.subscribe((v) => console.log(v)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment