我想使用像这样工作的PublishProcessor:
应该一直准备好接收和处理新的初始数据。
我已经准备好了简单的代码来测试它,但它没有用。
PublishProcessor processor = PublishProcessor.create();
processor.map(new Function<Integer, String>() {
@Override
public String apply(Integer o) throws Exception {
Thread.sleep(1000);
DevLog.d("test","executing "+o);
return String.valueOf(o)+"aaa";
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<String>() {
Subscription sub;
@Override
public void onSubscribe(org.reactivestreams.Subscription s) {
DevLog.d("test","onsubscribe "+s);
sub = s;
sub.request(1);
}
@Override
public void onNext(String s) {
DevLog.d("test","next "+s);
sub.request(1);
}
@Override
public void onError(Throwable t) {
DevLog.d("test","error "+t);
}
@Override
public void onComplete() {
DevLog.d("test","complete");
}
});
processor.onNext(666);
processor.onNext(123);
processor.onNext(456);
DevLog.d("test","nextsent");
我进入logcat的所有内容是:
我宁愿期待: