zoukankan      html  css  js  c++  java
  • [RxJS] Creation operators: empty, never, throw

    This lesson introduces operators empty(), never(), and throw(), which despite being plain and void of functionality, are very useful when combining with other Observables.

    empty:

    var foo = Rx.Observable.empty();
    // the same as
    var foo = Rx.Observable.create( function(observe) {
      observe.complete();
    })
    
    foo.subscribe(function (x) {
      console.log('next ' + x);
    }, function (err) {
      console.log('error ' + err);
    }, function () {
      console.log('done');
    });
    
    //done

    never(): do nothing

    var foo = Rx.Observable.never();
    // the same as
    var foo = Rx.Observable.create( function(observe) {
    })
    
    foo.subscribe(function (x) {
      console.log('next ' + x);
    }, function (err) {
      console.log('error ' + err);
    }, function () {
      console.log('done');
    });

    throw(): throw a Javascript error

    var foo = Rx.Observable.throw(new Error('blooom'));
    // the same as
    var foo = Rx.Observable.create( function(observe) {
      observe.error('bloom');
    })
    
    foo.subscribe(function (x) {
      console.log('next ' + x);
    }, function (err) {
      console.log('error ' + err);
    }, function () {
      console.log('done');
    });
  • 相关阅读:
    HashMap死循环造成CPU100%
    ArrayList升级为线程安全的List
    并发容器-ConncurrentHashMap
    并发容器-概览
    不可变性final
    CAS
    原子类-Adder累加器
    hue-使用mysql作为元数据库
    yhd日志分析(二)
    yhd日志分析(一)
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5389550.html
Copyright © 2011-2022 走看看