Skip to content

Instantly share code, notes, and snippets.

@mrijk
Created June 2, 2015 11:08
Show Gist options
  • Save mrijk/a3db35504e8e3839b2d2 to your computer and use it in GitHub Desktop.
Save mrijk/a3db35504e8e3839b2d2 to your computer and use it in GitHub Desktop.
RxJS test
var Rx = require('rx');
// Fake Mongo writing
var db = {
insert: function(x) {
console.log('Write to Mongo value impl: ' + x.key);
}
};
function myEventCollector(eventSource) {
var source = Rx.Observable.fromEvent(eventSource, 'message')
.groupByUntil(function(x) {return x.release;},
function(x) {return x.release;},
function(x) {return Rx.Observable.timer(10000);});
var subscription = source.subscribe(function(obs) {
obs.count().subscribe(function(x) {
console.log('count: ' + x);
db.insert(x);
});
});
}
function myBrilliantFunction() {
var source = Rx.Observable.interval(1000)
.take(5)
.sum();
var subscription = source.subscribe(
function (x) {
db.insert(x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
}
);
}
module.exports.myEventCollector = myEventCollector;
module.exports.myBrilliantFunction = myBrilliantFunction;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment