从
Rx Observables vs Dart Streams
在许多情况下,流和可观察对象的工作方式是相同的。然而,如果您习惯了标准的Rx可观察性,那么streamapi的一些特性可能会让您感到惊讶。我们在下面列出了一个表格,以帮助人们理解不同之处。
有关以下情况的更多信息,请阅读
Rx class documentation
.
ââââââââââââââââââââââââââââââââââââââââââââââ¬ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¬ââââââââââââââââââââââââââââââââââââââââ
â Situation â Rx Observables â Dart Streams â
ââââââââââââââââââââââââââââââââââââââââââââââ¼ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¼ââââââââââââââââââââââââââââââââââââââââ¤
â An error is raised â Observable Terminates with Error â Error is emitted and Stream continues â
â Cold Observables â Multiple subscribers can listen to the same cold Observable, each subscription will receive a unique Stream of data â Single subscriber only â
â Hot Observables â Yes â Yes, known as Broadcast Streams â
â Is {Publish, Behavior, Replay}Subject hot? â Yes â Yes â
â Single/Maybe/Complete ? â Yes â No, uses Dart Future â
â Support back pressure â Yes â Yes â
â Can emit null? â Yes, except RxJava â Yes â
â Sync by default â Yes â No â
â Can pause/resume a subscription*? â No â Yes â
ââââââââââââââââââââââââââââââââââââââââââââââ´ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ´ââââââââââââââââââââââââââââââââââââââââ