Last active
March 14, 2016 04:20
-
-
Save hanabokuro/d9cb31c54358f050e8bd to your computer and use it in GitHub Desktop.
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') | |
var source0 = | |
Rx.Observable.timer(0, 500) | |
.map(function () { | |
if(Math.floor(Math.random() * 2) == 0){ | |
return 'ズン' | |
}else{ | |
return 'ドコ' | |
} | |
}) | |
.share() | |
var source1 = Rx.Observable.return('').concat(source0) | |
var source2 = Rx.Observable.return('').concat(source1) | |
var source3 = Rx.Observable.return('').concat(source2) | |
var source4 = Rx.Observable.return('').concat(source3) | |
var source =Rx.Observable.zip(source4, source3, source2, source1, source0) | |
var logger = Rx.Observer.create( | |
function (data) { | |
process.stdout.write(data) | |
}) | |
source4.subscribe(logger) | |
source.subscribe(Rx.Observer.create( | |
function(data) { | |
var expected = ['ズン', 'ズン', 'ズン', 'ズン', 'ドコ'] | |
for(var i = 0;i < expected.length;i ++) { | |
if(expected[i] !== data[i]) { | |
return | |
} | |
} | |
logger.onNext('キヨシ') | |
logger.onCompleted() | |
process.exit() | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment