public
Created

Joins as Promises

  • Download Gist
joins-rx.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13
// requires rx.min.js, rx.joins.min.js
 
// Joins as promises
var obs1 = Rx.Observable.Return(42);
var obs2 = Rx.Observable.Return('foo');
 
var obs3 = Rx.Observable.When(obs1.And(obs2).Then(function (o1, o2) {
return o2 + ',' + o1
}));
 
obs3.Subscribe(function(x) {
console.log(x); // 'foo,42'
});

Almost identical to jQuery Deferred.

var def1 = $.Deferred().resolve(42);
var def2 = $.Deferred().resolve('foo');

var def3 = $.when(def1, def2).pipe(function(o1, o2) {
    return o2 + ',' + o1;
});

def3.done(function(x) {
    console.log(x); // 'foo,42'
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.