本文介绍了异步生成器和Observables有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
异步生成器:一个示例案例是可读流
Async generators: An example case is a readable stream
可观察的:处理异步数据流的基本协议
Observables: A fundamental protocol for processing asynchronous streams of data
这两种方法似乎都是解决异步数据流相同问题的不同方法.两者之间除了味觉上还有实际的区别吗?
These both seem like different ways of tackling the same problem of an asynchronous stream of data. Is there a practical difference between the two, besides a matter of taste?
推荐答案
从建议的API描述来看:
Judging from the proposed API descriptions:
- 可观察对象可以具有多个订阅者(广播),异步迭代器只能具有单个阅读器(单播)
- 可观察对象推送事件,而异步迭代器则需要轮询
- 诚然,
Observable
构造函数的懒惰性质确实会使线条模糊
- observables can have multiple subscribers (broadcast), asynchronous iterators can only have a single reader (unicast)
- observables push the events, while asynchronous iterators need to be polled
- admittedly, the lazy nature of the
Observable
constructor does blur the lines
可观察对象基本上是事件发射器,而异步迭代器可用于形成流式传输流.我还建议您阅读一般反应性理论.
Observables are basically event emitters, while asynchronous iterators can be used to form a streaming flow. I also recommend the General Theory of Reactivity as a good read.
这篇关于异步生成器和Observables有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!