Crystal中有定时器或间隔功能吗?
我检查了文档的计时器,间隔和Time类,但没有看到任何内容 .
来自JavaScript的 setInterval() 或 setTimeout() 之类的东西?
setInterval()
setTimeout()
超时时间为delay . 请注意,此API尚未最终确定,可能会在将来的版本中进行更改,甚至可能会再次暂时删除 .
对于间隔,目前没有任何东西可以保证精确的时间,但如果这没关系,并且近似间隔就足够了,那就像
spawn do loop do sleep INTERVAL do_regular_work end end sleep # Or some other workload, when the main fiber quits so will the program and thus all other fibers.
1 回答
超时时间为delay . 请注意,此API尚未最终确定,可能会在将来的版本中进行更改,甚至可能会再次暂时删除 .
对于间隔,目前没有任何东西可以保证精确的时间,但如果这没关系,并且近似间隔就足够了,那就像