[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 ...
随机推荐
- 看android的书的体会
android书上面的代码有时候有问题,可以在网上搜索这些功能.网上和官方文档里面有很好的说明和例子.
- ruby 知识点
$LOAD_PATH 执行 require 读取文件时搜索的目录名数组,也可以写作 $: 创建 URI 的时候可以直接这样 URI("http://www.dy2018.com/i/9751 ...
- 反序列化 DateTime对象问题
今天在Android的Json反序列化过程中,Date类型无法转化成自己想要的格式,鉴于之前在C#的反序列话中也遇到过这个问题,解决的同时,顺手做个总结,供自己及需要的人日后查阅. 将 ...
- 第一次启动MySQL时报错
[root@localhost~]#/usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mys ...
- ON DUPLICATE KEY UPDATE 当记录不存在时插入,当记录存在时更新
MySQL 当记录不存在时插入,当记录存在时更新网上基本有三种解决方法.第一种:示例一:插入多条记录假设有一个主键为 client_id 的 clients 表,可以使用下面的语句:INSERTINT ...
- IO流文件字符输入输出流,缓冲流
由于字节输入输出流在操纵Unicode字符时可能有乱码现象 于是就有了操作字符的输入输出流 Reader ,Writer和他们的子类FileReader,FileWrite(其实就是用来辅助构造的 W ...
- QC 2.0为啥可以快充
根据高通给出的数据,Quick Charge 2.0 A级标准规定的最大充电电流为3A,如果在5V的情况下,充电功率就为15W,因此充电速度要比最高支持10W的Quick Charge 1.0技术更快 ...
- phpcms v9版本二次开发四步曲
今晚看了一下PHPCMS V9版本,做一个实例抛砖引玉,其实很简单,以下是二次开发的一个实例以旅游模块为例1. 在phpcms\modules目录下建立一个文件夹tour2. 在phpcms\m ...
- 11061160_11061151_Pair Project: Elevator Scheduler软件工程结对编程作业总结
软件工程结对编程作业总结 11061160 顾泽鹏 11061151 庞梦劼 一.关于结对编程 这次的软工任务既不是单打独斗的个人任务,也不是集思广益的团队项目,而是人数为两人的结对编程.两个人合 ...
- EF学习
一.EF介绍 实体框架 Entity Framework 是ADO.NET 中的一组支持开发面向数据的软件应用程序的技术.在 EF 中的实体数据模型(EDM)由以下三种模型和具有相应文件扩展名的映射文 ...