Skip to content

petite-utilsDocs


函数: repeatRun()

repeatRun(fn, __namedParameters, params?): StopRepeat

repeat call function

参数

参数名类型描述
fnRepeatFnwill be called repeatly
__namedParametersRepeatOptions-
params?unknownparams pass to fn

返回值

StopRepeat

stopFunction to stop repeat

示例s

pass a arrow function to repeat

ts
repeatRun((repeatTimes, stop) => {
 console.log(repeatTimes)
if (repeatTimes === 5) {
   stop() // stop function from fn params
 }
})

pass a function definition to repeat and stop it by repeat return value

ts
let stop = repeatRun(sayHi, { interval: 1000 })
function sayHi(repeatTimes) {
 console.log(repeatTimes)
 if (repeatTimes === 5) {
  stop() // stop from repeatRun return value
 }
}

源码

utils/repeatRun.ts:57

Released under the MIT License.