2016-12-08 7 views

答えて

1

簡単な例:

someObservable.repeatUntil(new BooleanSupplier() { 
    @Override 
    public boolean getAsBoolean() throws Exception { 
     return false; //repeat when upstream Observable calls onComplete 
     return true; //don't repeat and go downstream 
    } 
}); 

公式RxJavaのjavadocはhereです。 RepeatUntilの説明はhereです。

0

二回連続した番号ごとに500ミリ秒を出力する例:

public class Application { 

    public static void main(String[] args) throws InterruptedException { 

     final long startTimeMillis = System.currentTimeMillis(); 
     Observable.interval(500, TimeUnit.MILLISECONDS) 
      .take(5) //takes the first five emissions from the observable source 
      .repeatUntil(() -> System.currentTimeMillis() - startTimeMillis > 5000) 
      .subscribe(System.out::println); 

     Thread.sleep(6000); 
    } 
} 

出力:

0 
1 
2 
3 
4 
0 
1 
2 
3 
4