Is ReplaySubject(1) the same as AsyncSubject()?

怎甘沉沦 提交于 2019-12-12 10:01:42

问题


I'm currently using this to perform notifications:

  /**
   * Create notifications that broacast
   * the entire set of entries.
   */
  protected notify = new ReplaySubject<E[]>(1);

IIUC I can switch out the ReplaySubject<E[]>(1) with AsyncSubject<E[]>()?

Would this be an apple to apple switch or might here be semantic differences?


回答1:


No, they're very much not the same.

ReplaySubject(1) will always replay the latest emission no matter when the observer subscribes. It can emit any number of times.

AsyncSubject ignores all emissions until the observable completes, then emits the last emitted value. It can only ever emit once (at most) and when it does, it will also complete.



来源:https://stackoverflow.com/questions/52335556/is-replaysubject1-the-same-as-asyncsubject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!