zoukankan      html  css  js  c++  java
  • [RxJS] Transformation operators: delay and delayWhen

    This lessons teaches about delay and delayWhen: simple operators that time shift.

    delay(number | date)

    var foo = Rx.Observable.interval(500).take(5);
    
    /*
    --0--1--2--3--4|
     delay(1000)
    -----0--1--2--3--4|
    */
    
    // delay(1000)
    var result = foo.delay(1000);
    
    result.subscribe(
      function (x) { console.log('next ' + x); },
      function (err) { console.log('error ' + err); },
      function () { console.log('done'); },
    );
    var foo = Rx.Observable.interval(500).take(5);
    
    /*
    --0--1--2--3--4|
     delay(date)
    -----0--1--2--3--4|
    */
    
    
    var date = new Date(new Date().getTime() + 1000); 
    var result = foo.delay(date);
    
    result.subscribe(
      function (x) { console.log('next ' + x); },
      function (err) { console.log('error ' + err); },
      function () { console.log('done'); },
    );

    delayWhen( function :Observable): accept a function which return an observable:

    var foo = Rx.Observable.interval(500).take(5);
    
    /*
    --0--1--2--3--4|
     delayWhen(x => --------0--------...)
    --------0--------1--------2--------3--------4|
    */
    
    // delay(1000)
    var result = foo.delayWhen(x =>
      Rx.Observable.interval(x * 1000) // For each foo, it will delay 1000 * x, so '2' --> 2000, '3' ---> 3000
    );
    
    result.subscribe(
      function (x) { console.log('next ' + x); },
      function (err) { console.log('error ' + err); },
      function () { console.log('done'); },
    );
  • 相关阅读:
    调度算法的评价指标
    进程调度的时机 切换与过程调度方式
    处理机调度 概念和层次
    线程概念 多线程模型
    进程通信
    进程的状态与转换
    进程的定义
    系统调用
    面试题3
    第2章Arduino UNO板结构说明
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5535700.html
Copyright © 2011-2022 走看看