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的更多相关文章

  1. [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 ...

  2. [RxJS] Handling a Complete Stream with Reduce

    When a stream has completed, you often need to evaluate everything that has happened while the strea ...

  3. Angular: 使用 RxJS Observables 来实现简易版的无限滚动加载指令

    我使用 angular-cli 来搭建项目. ng new infinite-scroller-poc --style=scss 项目生成好后,进入 infinite-scroller-poc 目录下 ...

  4. Angular基础(八) Observable & RxJS

    对于一个应用来说,获取数据的方法可以有很多,比如:Ajax, Websockets, LocalStorage, Indexdb, Service Workers,但是如何整合多种数据源.如何避免BU ...

  5. RxJS之组合操作符 ( Angular环境 )

    一 merge操作符 把多个 Observables 的值混合到一个 Observable 中 import { Component, OnInit } from '@angular/core'; i ...

  6. [RxJS] RefCount: automatically starting and stopping an execution

    With the connect() method on a ConnectableObservable, the programmer is responsible for avoiding lea ...

  7. rxjs 入门--环境配置

    原文: https://codingthesmartway.com/getting-started-with-rxjs-part-1-setting-up-the-development-enviro ...

  8. [RxJS] Combination operators: concat, startWith

    Some Observables may complete, and we may want to append another Observable to the one which just co ...

  9. [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 ...

随机推荐

  1. Android让你的Toast变得炫酷

    一.代码: app.gradle: dependencies{ compile 'com.sdsmdg.tastytoast:tastytoast:0.0.2'} java代码: TastyToast ...

  2. 定义Foo() 函数,弹出对话框提示当前选中的是第几个单选框

    function foo(){ var ele = document.getElementsByName("radioElement"); for(var i = 0;i<e ...

  3. SQL用row_number进行高速循环

    SQL用row_number进行循环查询 declare @count int=0,@R int=0select row_number()over(order by RoomID) as R,* in ...

  4. java学习——集合框架(Collection,List,Set)

    集合类的由来: 对象用于封装特有数据,对象多了需要存储,如果对象的个数不确定,就使用集合容器进行存储. 集合特点:1,用于存储对象的容器.2,集合的长度是可变的.3,集合中不可以存储基本数据类型值. ...

  5. YesFinder - 网页文件管理系统 V2.0

    2.0版增加了模态框并重写了右键菜单插件.界面改为全中文.使用方式更加灵活. 同时,文件及目录改名更方便,直接双击名称就可改名. 这是DEMO的效果图. 1.功能上的主要改进是可以双击改文件/目录名称 ...

  6. 3D 灯光介绍

    光特性 参考OpenGL的光照模型,把光分成4种独立的成分: 环境光 散射光 镜面光 发散光 环境光:ambient light 环境光是那些在环境中进行了充分的散射,无法分辨其方向的光.它会均匀的照 ...

  7. memcache实例

    <?php class demo { private $str_attr; private $int_attr; public function __get($name) { return $t ...

  8. 限制对比度自适应直方图均衡(Contrast Limited Adaptive histgram equalization/CLAHE)

    转自:http://www.cnblogs.com/Imageshop/archive/2013/04/07/3006334.html 一.自适应直方图均衡化(Adaptive histgram eq ...

  9. 『安全工具』Nmap 强悍的端口扫描工具

    作为时下流行的端口扫描工具,Nmap有因其扫描的隐密性有“端口扫描之王”之称 上图是黑客帝国(The Matrix)中崔妮蒂用Nmap入侵核发电站的能源管理系统 0x 01 Nmap介绍 Nmap是一 ...

  10. ViewPager+Fragment的结合使用,实现QQ界面的理解

    http://www.cssxt.com/html/2449/2449.html 效果如图: 实现代码解析:MainActivity.java1.引入布局文件2.4个标题控件的初始化以及点击事件的监听 ...