new Polling(options)
轮询类
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | 轮询选项 Properties
|
- Source
Example
const pollingInstance = new Polling({
// 轮询的请求
request:()=>fetch('/data'),
// 可选:在此判断是否继续轮询,不传默认持续轮询
needToPolling: (res) => {
const undoneCount = 1;
return undoneCount > 0;
},
});
// 每次轮询请求回来的数据更新事件
pollingInstance.addEventListener('update',(res)=>{
console.log(res)
})
// 轮询结束
pollingInstance.addEventListener('end',()=>{
console.log('end')
})
// 开始轮询
pollingInstance.start()
// 主动结束
pollingInstance.stop()
Extends
- EventTarget
Methods
(async) start()
开始轮询
- Source
(async) stop()
停止
- Source