0
条件またはタイムアウトを待つ必要があります。私は次のアプローチを思いついたが、あまりにも多くのことが起こっている。どのように私はこれを圧縮することができます。Observable.intervalを使用してリモートデータまたはタイムアウトを待機する
import io.reactivex.Observable;
import java.util.concurrent.TimeUnit;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.ThreadLocalRandom;
public class Test{
public static void main(String[] args)throws InterruptedException{
AtomicBoolean toggle = new
java.util.concurrent.atomic.AtomicBoolean(true);
Observable.interval(0,50, TimeUnit.MILLISECONDS)
.takeWhile(l->l<(20000/50))
.takeWhile(l-> toggle.get())
.observeOn(Schedulers.io())
.map(l->{ return (l>ThreadLocalRandom.current()
.nextInt(5, 20 + 1))?true:false;})
// The above map will call a remote function to check for some condition
.observeOn(Schedulers.computation())
.filter(exist->exist)
//.takeWhile(exist->!exist)
.map(l->{toggle.set(false);return l;})
.map(l->{System.out.println("Called at "+l);return l;})
.blockingSubscribe();
}
}
ありがとうございました。私は1を探していた。 –
isOnSuccessが呼び出されるのは、isConditionTrueがtrueを返す場合です。これがタイムアウトしたかどうかはどうやって調べるのですか? –
@JaganVeeraraghavanあなたは 'Maybe.isEmpty'を使うことができます。 –