[RxJS] Observables can complete
The Observer object has the functions next() and error(). In this lesson we will see the other (and last) function available on observers, complete(), and its purpose.
Completion is an important concept, as we will see later on. Imagine if you want to concatenate two observables. You can only do that if the first one ends. Then you know that the second observable takes over after that.
Completion is also important in other ways. For instance, let's say that observer is only interested in the last value that observable produced. This last can only be determined if there is a way to know that the observable has finished and won't deliver any values anymore.
var bar = Rx.Observable.create(function (observer) {
try {
console.log('Hello');
observer.next(42);
observer.next(100);
observer.next(200);
setTimeout(function () {
observer.next(300);
observer.complete();
}, 1000);
} catch (err) {
observer.error(err);
}
});
bar.subscribe(
function nextValueHandler(x) {
console.log(x);
},
function errorHandler(err) {
console.log('Something went wrong: ' + err);
},
function completeHandler() {
console.log('done');
}
);
[RxJS] Observables can complete的更多相关文章
- [RxJS] Observables can throw errors
Whenever we are writing code, we need to remember that things may go wrong. If an error happens in a ...
- [RxJS] Handling a Complete Stream with Reduce
When a stream has completed, you often need to evaluate everything that has happened while the strea ...
- Angular: 使用 RxJS Observables 来实现简易版的无限滚动加载指令
我使用 angular-cli 来搭建项目. ng new infinite-scroller-poc --style=scss 项目生成好后,进入 infinite-scroller-poc 目录下 ...
- Angular基础(八) Observable & RxJS
对于一个应用来说,获取数据的方法可以有很多,比如:Ajax, Websockets, LocalStorage, Indexdb, Service Workers,但是如何整合多种数据源.如何避免BU ...
- RxJS之组合操作符 ( Angular环境 )
一 merge操作符 把多个 Observables 的值混合到一个 Observable 中 import { Component, OnInit } from '@angular/core'; i ...
- [RxJS] RefCount: automatically starting and stopping an execution
With the connect() method on a ConnectableObservable, the programmer is responsible for avoiding lea ...
- rxjs 入门--环境配置
原文: https://codingthesmartway.com/getting-started-with-rxjs-part-1-setting-up-the-development-enviro ...
- [RxJS] Combination operators: concat, startWith
Some Observables may complete, and we may want to append another Observable to the one which just co ...
- [Reactive Programming] Async requests and responses in RxJS
We will learn how to perform network requests to a backend using RxJS Observables. A example of basi ...
随机推荐
- 项目中用到的input 遇到的问题的归类
input 前几天 为了这个词 用在搜索框被我们总监喷,为了加强印象,我把它记录下来 最原始的造型 <input type="text" value="搜索&quo ...
- spring-junit的标注总结
如果在测试类的类名上面添加了注解 @ContextConfiguration("meta/springConfigured.xml") 如何在标注了@Test的方法里面获取上面xm ...
- java里面List和Array的区别是什么?
java里面的List和Array的区别是什么? 1:数组是定长,list是自动增长.2:数组效率高,list效率低.总结:数组牺牲功能增加效率,list牺牲效率增加功能. http://bbs.cs ...
- Ecstore关于finder的默认的参数row的数据不见了的一些小问题?
在finder中,我们经常对默认的参数row进行数据的编辑处理,然而,在实际处理中,会遇到这么一个问题,该处理的数据不见了,造成这一原因的重要原 因是因为在设置的时候,把某些字段屏蔽掉了,导致返回的r ...
- 《CSS网站布局实录》学习笔记(四)
第四章 CSS网站元素设计 4.1 网站导航 网站导航是网站中最重要的元素.从形式上看,网站导航主要分横向导航.纵向导航.下拉及多级菜单导航灯3种常见形式. 横向导航:作为门户网站的设计而言,主导航一 ...
- ImageView的学习
学习安卓时我还是习惯看懂手册,虽然是英文但是可以获得的东西必然也是更多的,否则自己只能停留在拾人牙缝的水平,虽然我是初学,但是还是分享一些自己的学习过程及方法. 从手册中我们看以知道,ImageVie ...
- win8发布 wcf问题
WCF services don’t run on IIS 8 with the default configuration, because the webserver doesn’t know, ...
- 如何安装Oracle Database 11g数据库
先选择你适合你的系统版本,32位系统的请选择32位的,64位系统可以使用32位也可以使用64位,建议采用64位的! 适用于 Microsoft Windows(32 位)的 Oracle Databa ...
- iOS中使用Localizable.strings适配App在不同语言下文本的显示
iOS开发中,若是使用xib或storyboard搭建界面视图,视图中固定显示的文本内容可以用localized添加不同语言适配.但是在实际中会有动态加载的文本,这些文字的适配就需要NSLocaliz ...
- centos 安装 vsftp
vsftp是一款在Linux发行版中最受推崇的FTP服务器程序.特点是小巧轻快,安全易用.下面介绍CentOS下安装和简单配置 vsftp 这个服务软件. 在Linux下可以搭建本地YUM库来进行系统 ...