I'd like to use RxJS to "bridge" async world of events with sync world. Specifically I want to create an function which returns an array of events collected during some time interval.
I can create Observable which does what I want
var source = Rx.Observable
.interval(100 /* ms */)
.bufferWithTime(1000).take(1)
I can print correct values just fine
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + JSON.stringify(x));
},
function () {
console.log('Completed');
});
This prints
[0,1,2,3,4,5,6,7,8]
Completed
But want I want is to assign this array to variable. Conceptually I want something like
var collectedDuringSecond = source.toPromise.getValue()
The idea is that getValue would block so after the line above is done collectedDuringSecond will contain [0,1,2,3,4,5,6,7,8]