Created
June 2, 2015 11:08
-
-
Save mrijk/a3db35504e8e3839b2d2 to your computer and use it in GitHub Desktop.
RxJS test
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
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