Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJava - subcribe and wait until a variable is true

I've searched but found nothing so far... or I'm just confuse what should I look for.

What I'm trying to do is, a subscription will be made and will check if variable X is TRUE. If not it will wait until it turns to TRUE and execute the succeeding events.

I'm looking into the repeat() method but not sure how it works... any suggestion is very much appreciated...

like image 940
SquareBox Avatar asked Sep 01 '16 03:09

SquareBox


1 Answers

Just emit your variable in a observable, and filter it. You can use a PublishSubject to emit your variable.

 PublishSubject<Boolean> subject = PublishSubject.create();


 void updateBoolean(boolean b) {
      subject.onNext(b);
 }


 // latter in your code
 subject.filter(b -> b)
        .subscribe(b -> /* do something here only if b is true */); 
like image 187
dwursteisen Avatar answered Sep 20 '22 22:09

dwursteisen