Skip to content

Instantly share code, notes, and snippets.

@cwharris
Created September 2, 2013 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwharris/6416908 to your computer and use it in GitHub Desktop.
Save cwharris/6416908 to your computer and use it in GitHub Desktop.
What should this be doing exactly?
var Rx = require('rx');
var a = new Rx.Subject();
var b = new Rx.Subject();
var c = new Rx.Subject();
var resA = Rx.Observable
.when(
a.and(b)
.then(function (a, b) { return a + b; })
);
resA.subscribe(function () {
console.log(arguments);
});
a.onNext('0');
a.onNext('1');
a.onNext('2');
a.onNext('3');
a.onNext('4');
a.onNext('5');
a.onNext('6');
a.onNext('7');
a.onNext('8');
a.onNext('9');
b.onNext('0');
b.onNext('1');
@cwharris
Copy link
Author

cwharris commented Sep 2, 2013

Result:
cwharris$ node app
{ '0': '00' }
{ '0': '11' }

@cwharris
Copy link
Author

cwharris commented Sep 2, 2013

Shouldn't I only be getting one event out of this? Why is it acting exactly like zip?

@mattpodwysocki
Copy link

What you are seeing is correct behavior. This isn't a once only operation. It's just a when either happens in any order, then produce this result. See this test for further details

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