Function: polling()
Call Signature
ts
function polling(factory, interval?): () => void;Repeatedly calls a factory on an interval. Returns a stop function for interval mode, or waits for a matching result when PollingOptions are passed. 按间隔反复调用工厂函数;传入 PollingOptions 时等待匹配结果。
Parameters
| Parameter | Type |
|---|---|
factory | () => Promise<unknown> |
interval? | number |
Returns
() => void
Example
ts
let count = 0
const stop = polling(async () => {
count++
console.log('poll:', count)
if (count >= 3) stop()
}, 100)
typeof stop // => 'function'Since
1.0.0
Call Signature
ts
function polling<T>(factory, options): Promise<T>;Repeatedly calls a factory on an interval. Returns a stop function for interval mode, or waits for a matching result when PollingOptions are passed. 按间隔反复调用工厂函数;传入 PollingOptions 时等待匹配结果。
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
factory | () => Promise<T> |
options | PollingOptions<T> |
Returns
Promise<T>
Example
ts
let count = 0
const stop = polling(async () => {
count++
console.log('poll:', count)
if (count >= 3) stop()
}, 100)
typeof stop // => 'function'Since
1.0.0