zoukankan      html  css  js  c++  java
  • [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');
      }
    );
  • 相关阅读:
    防止sql注入的小函数 以及一些小验证
    PHP几个防SQL注入攻击自带函数区别
    redis配置文件.conf和常用配置
    redis常用命令
    redis数据类型
    redis的安装和简单操作
    yum CentOS7安装mysql
    Linux安装mysql
    firewall-cmd 常用命令
    解决linux下启动tomcat找不到jdk
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5376512.html
Copyright © 2011-2022 走看看