What does observer.complete() do?

末鹿安然 提交于 2019-12-08 02:41:40

问题


In rxjs what exactly does the observer.complete() do after observer.next() ?


回答1:


From the documentation observer.complete notifies the Observer that the Observable has finished sending push-based notifications.

In the other hand, observer.complete it's a callback function and an Observable calls this method after it has called next() for the final time, if it has not encountered any errors.




回答2:


In ReactiveX library, there are two types of messages.

First ones are ordinary messages. Ordinary messages are the ones sent with .next() and there can be 0-many of them.

Second type are notifications. These can be of two types - error and success. The error is sent with .error() and give some error details in it (like exception) and success is sent with .complete() meaning that there will intentionally be no messages. Every observable should end with a single error or a single success notification.



来源:https://stackoverflow.com/questions/48278920/what-does-observer-complete-do

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