📜  轮询间隔 javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:22.490000             🧑  作者: Mango

代码示例1
var sleep = time => new Promise(resolve => setTimeout(resolve, time))
var poll = (promiseFn, time) => promiseFn().then(
             sleep(time).then(() => poll(promiseFn, time)))

// Greet the World every second
poll(() => new Promise(() => console.log('Hello World!')), 1000)