-
-
Save literadix/a05409bf9e29bc5fa03a to your computer and use it in GitHub Desktop.
RxJS equivalent of async.parallel
This file contains hidden or 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 zipper = function () { | |
// Turning arguments from an object into an actual array so we can use things like map() | |
return Array.prototype.slice.call(arguments); | |
}; | |
var array; // Given some array of Observables that you want zipped together | |
// Or the more classical case where given an array of data to operate on, simply map them into observables | |
var data = [0, 1, 2, 3, 4, 5]; | |
array = data.map(function (element) { | |
return Rx.Observable.create(function (observer) { | |
observer.onNext(element); | |
}); | |
}); | |
// After transforming | |
Rx.Observable.zip.apply(Rx.Observable, array.concat(zipper)).subscribe(function (zipped) { | |
// Yay! Zipped data! | |
console.log(zipped); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment