如何在JavaScript中以特定的偏移/间隔持续时间调用函数/通知?
在我最近的项目中,我遇到了一个情况,必须根据特定时间表向客户发送通知。例如:时间表值是 8s,14s,20s ,然后在8s之后发送第一次通知,接下来是在14s上,最后一个是20s。 我们如何实现此功能?
In my recent project, I came across a situation where I have to send a notifications to client based on specific schedule. For an example: schedule value is 8s,14s,20s then first notification will be send after 8s, next is on 14s and last is on 20s.
How can we achieve this functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会做这样的事情:
I would do something like this:
您可以做类似的事情:
在这里,您可以根据要求添加多个间隔。对于您的用例,Settimeout是唯一的选项,因为您需要在不同的间隔内调用通知。
You can do something like this:
Here, you can add multiple interval based on your requirement. For your use case, setTimeout is the only option as you need to call notifications on different intervals.