天天看點

走進rxjs的世界 - 萬物皆流 - Everything is a stream

走進rxjs的世界 - 萬物皆流 - Everything is a stream

The caller of our pollTasks() method just gets an observable, which is emitting content every 10 seconds.

調用pollTasks方法,隻會傳回一個Observable對象,這個Observable對象subscribe之後,會每隔10秒産生内容。調用unsubscribe關閉。

Also the flatMapLatest call is really interesting – any calls generated by previous events are canceled, including their in-flight HTTP method calls. Try doing that with a promise!

flagMapLatest是一個強力方法,這裡将其當作一種engine使用:所有基于之前發生的事件觸發的調用都會自動被cancel,包括正在進行中的in-flight HTTP調用。很難想象使用promise實作類似的方法,會花費多大的工作量。

參考文獻