• [RxJS] Schedular basic


      subscribeOn() {
        // Changes source execution
        // only used once
        of(1).pipe(
          subscribeOn(async)
        )
        .subscribe({
          next: x => console.log(x),
          complete: () => console.log('3')
        })
        console.log('2')
    
        //2 1 3
      }
    
      observeOn() {
        // Changes notifications execution  (next, error, complete)
        // Can be used before each operators
      }
    
      queueSchedular() {
        // execute synchronously
        // tasks execute in order
        // waits until current task ends before exeucting next one
        // performant (precedes event loop)
    
        queue.schedule(() => console.log(1)) // sync
        console.log(2) // sync
        queue.schedule(() => console.log(3)) // sync
        
        // 1 2 3
    
        queue.schedule(() => {
          // when nested queue, change behavior
          queue.schedule(() => console.log(1)) // async
          console.log(2) // sync
          queue.schedule(() => console.log(3)) // async
        })
    
        // 2 1 3
      }
    
      asapSchedular() {
        // executes asynchronously (micro)
        // Tasks execute before next tick
        // Relays on Promises
        // Performant (precedes event loop)
        setTimeout(() => console.log(1)) // macro
        asap.schedule(() => console.log(2)) // micro
        queue.schedule(() => console.log(3)) // snyc
    
        // 3 2 1
      }
    
      asyncSchedular() {
        // Executes asynchronously (macro)
        // Relays on setInterval
        // less performant (use event loop)
        async.schedule(() => console.log(1)) // macro
        asap.schedule(() => console.log(2)) // micro
        queue.schedule(() => console.log(3)) // snyc
    
        // 3 2 1
      }
    
      cancelling() {
        const s = new AsyncScheduler(AsyncAction)
        const DELAY = 0;
        let subscription = s.schedule(v => console.log(v), DELAY, '1')
        s.schedule(v => console.log(v), DELAY, '2')
        console.log('3')
        subscription.unsubscribe();
    
        // 3 2 
        // 1 got cancelled
      }
    
      internalTime() {
        const s = new AsyncScheduler(AsyncAction)
        const DELAY = 2000; 
        const start = Date.now()
    
        s.schedule(v => console.log(v), DELAY, 1)
        s.schedule(v => console.log(v), DELAY, 2)
        s.schedule(v => console.log(`${s.now() - start}ms`), DELAY)
        console.log(3)
    
        // 3 1 2 2008ms
      }
  • 相关阅读:
    js动态添加、删除行
    java内存问题排查及分析
    IDE 热部署配置
    Target JRE version (1.7.0_79) does not match project JDK version (java version "1.8.0_171"), will use sources from JDK: 1.7
    快速排序
    归并排序思想
    算法总结
    百度2013校园招聘笔试题(含整理的答案)
    浙江省委书记(习):加快推进节约型社会建设
    申论方面的经验
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12791548.html
Copyright © 2020-2023  润新知