zoukankan      html  css  js  c++  java
  • pauseable 库

    pauseable.js

    https://www.npmjs.com/package/pauseable

    Pauseable allows you to pause event emitters, timeouts, and intervals. It can group multiple of these pauseable objects and pause entire groups.

    Using pauseable with EventEmitter

    const pauseable require('pauseable');
    const EventEmitter require('events').EventEmitter;
     
    var ee new EventEmitter();
     
    ee.on('foo'(=> ... });
     
    // ...later
    pauseable.pause(ee);
     
    // this event will not be immediately fired
    // instead, it will be buffered
    ee.emit('foo''hellow');
     
    // ...much later
    // the 'foo' event will be fired at this point
    pauseable.resume(ee);

     

    Comes with pauseable setTimeout and setInterval too

    var timeout pauseable.setTimeout((=> {
      // this will take 8 seconds total to execute
      // not 5
    }5000);
     
    // pause timeout after 2 secs
    setTimeout((=> {
      timeout.pause();
      timeout.isPaused()// true
      
      // resume after 3
      setTimeout((=> {
        timeout.resume();
      }3000);
    }2000);

    The function and ms arguments are interchangeable. Use whichever way you prefer!

    var interval pauseable.setInterval(5000(=> {
      // this is called after 5 seconds
      // then paused for 2 seconds
      interval.pause(2000);
    });
     
     

    Motive

    Javascript is event based by nature. When developing large scale applications that are completely event based, it becomes complicated to pause the streaming of events, because Javascript never "sleeps". It becomes even more complicated to pause timeouts and intervals, having to keep track of when they were paused so they can be resumed with the correct time again.

    That's where this module comes in. Pauseable helps manage pausing and resuming your application or part of it. It works with EventEmitter, with setInterval and setTimeout.

     用途:

    1、 页面游戏, 例如花朵和僵尸, 可以使用魔法将僵尸定住一段时间, 时间到后僵尸继续行动。

    2、 XX功能关闭, 对于XX功能是由事件监听驱动的, 可以使用这个功能临时关闭掉, 需要的时候再打开。

  • 相关阅读:
    Oracle UTL_HTTP(收集汇总有用资料)
    UTL_HTTP Call a Web Service and Pass Parameters as Part of the URL
    How to Create Modifiers Using the API QP_MODIFIERS_PUB.PROCESS_MODIFIERS
    HOW to Use QP_PREQ_PUB.PRICE_REQUEST API to Price an Item
    Sample Code for Qp_preq_pub.Price_request Api to Simulate an Ask for Promotion Modifier
    修改量更新API
    关于销售订单高级定价的一点疑惑
    Useful Scripts for E-Business Suite Applications Analysts
    OPEN A PO ORDER OR SO ORDER
    更改EBS服务器域名/IP
  • 原文地址:https://www.cnblogs.com/lightsong/p/10841787.html
Copyright © 2011-2022 走看看