setTimeout in Node.js loop

后端 未结 8 1586
眼角桃花
眼角桃花 2020-12-06 05:16

I\'m a bit confused as to how setTimeout works. I\'m trying to have a setTimeout in a loop, so that the loop iterations are, say, 1s apart. Each l

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 05:55

    You're calling makeRequest() in your setTimeout call - you should be passing the function to setTimeout, not calling it, so something like

    setTimeout(makeRequest, 1000);
    

    without the ()

提交回复
热议问题