Last active
August 29, 2015 13:56
-
-
Save searler/8904778 to your computer and use it in GitHub Desktop.
RxJava I/O using recursive scheduler
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
public class Recursive { | |
public static void main(String[] args) throws InterruptedException { | |
final Scheduler scheduler = Schedulers.newThread(); | |
Observable<Character> obs = Observable | |
.create(new OnSubscribeFunc<Character>() { | |
@Override | |
public Subscription onSubscribe( | |
final Observer<? super Character> observer) { | |
return scheduler.schedule(new Action1<Action0>() { | |
@Override | |
public void call(Action0 inner) { | |
Character c = ' '; | |
try { | |
c = (char) System.in.read(); | |
} catch (IOException e) { | |
} | |
observer.onNext(c); | |
if (c.equals('!')) | |
observer.onCompleted(); | |
else | |
inner.call(); | |
} | |
}); | |
} | |
}); | |
obs.toBlockingObservable().forEach(new Action1<Character>() { | |
@Override | |
public void call(Character c) { | |
System.err.print(c); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment