I'm new to reactive programming and have difficulties using "everything can be a stream" mantra. I'm considering the following scenario - I have a stream of websocket events definied like this:
Rx.Observable.create((observer) => {
io.on('connect', function(socket){
socket.on("enroll", function(player) {
observer.next({
event: 'enroll',
player,
socket
});
});
socket.on('resign', function(player){
observer.next({
event: 'resign',
player,
socket
});
});
});
return {
dispose: io.close
};
});
Then I can do something like
enrollmentStream = events$
.filter(find({ event: "enroll" }))
.map(pick('player'));
And likewise
resignationStream = events$
.filter(find({ event: "resign" }))
.map(pick('player'));
I would like to gather enrolled players in a stream which would batch them in 4's but obviously this should be done only for users which are in enrollment stream but are not in resignationStream or at least the last event was enrollment. How do I do this?
Here is the marble diagram.
There are 5 players which enroll. Game starts when there are 4 players enrolled. Note that the second player (violet one) enrolls but then resigns so the game does not start with blue marble but with the next - yellow - cause only after that there are really 4 players ready.
Probably there should be some stream operation like "without"... is there?
