简体   繁体   中英

Call the lastvalue after takeUntil

I have an service call on which i am checking whether it returns true or false every 5 seconds.

notifier(){
   return Rx.Observable.of(true) // based on some condition       
}

executeAnotherApiCall(){

}

const interval = Rx.Observable.interval(5000)


interval
  .takeUntil(() => this.notifier())
  .map((x) => this.executeAnotherApiCall())

The problem is executeAnotherApiCall is never called, it directly goes to calling method subscribe method.

Is there a way to execute another method/function after takeUntil() returns true.

timer(2000) works that it emit 0 after 2 second then complete. TakeUntil wait when this.notifier() will be complete and stops emit values. Your interval emit first value after 5 seconds so this case will never occur because takeUntil will stop emit values.

When you change the parameters, for example:

const interval = Rx.Observable.interval(1000)
const notifier = Rx.Observable.timer(2000)

your executeAnotherApiCall() method in this case will run once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM