Class: Polling

polling.Polling(executor, optionsopt)

new Polling(executor, optionsopt)

轮询类。
Parameters:
Name Type Attributes Description
executor function 执行函数,返回值为 Promise(带有 then 方法)时会进行异步处理。
options Object <optional>
其他选项。
Properties
Name Type Attributes Default Description
interval number <optional>
1000 轮询间隔(毫秒)。
breakOnError boolean <optional>
false 执行函数有异常(包括 Promise 的拒绝状态)时是否中断轮询。
Source:
Example
const polling = new Polling(() => {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log('executed');
      resolve();
    }, 1000);
  });
}, {
  interval: 2000
});
polling.start();

Methods

execImmediately()

在当前轮询结束后马上执行一次执行函数。
Source:

start()

启动轮询。
Source:

stop()

停止轮询。
Source: