ReplaySubject(1)是否与AsyncSubject()相同? [英] Is ReplaySubject(1) the same as AsyncSubject()?

查看:63
本文介绍了ReplaySubject(1)是否与AsyncSubject()相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用它来执行通知:

I'm currently using this to perform notifications:

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

IIUC我可以用 AsyncSubject< E []>()切换 ReplaySubject< E []> 吗?

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?

推荐答案

不,它们非常不同.

ReplaySubject(1)将始终重播最新的发射,无论观察者何时订阅.它可以发射任意次.

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

AsyncSubject忽略所有发射,直到可观察值完成为止,然后发射最后一个发射值.它只能发射一次(最多),当发射一次时,它也会完成.

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.

这篇关于ReplaySubject(1)是否与AsyncSubject()相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆