A
A
atamanenko2017-01-15 13:41:26
JavaScript
atamanenko, 2017-01-15 13:41:26

How to perform sequential actions after a certain period of time?

There is a conditional file that contains in each line a json array in approximately the following format:
[time, data]
Time - milliseconds, for example:
[0, data]
[840, data]
[2000, data] It is
necessary that after starting the script with the corresponding delay sent data to the user through the socket.
How to implement it correctly?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xfg, 2017-01-15
@atamanenko

Look for a task manager with the possibility of deferred task processing. For example, kue can queue pending tasks https://github.com/Automattic/kue#delayed-jobs and then write a handler for these tasks that will do something, for example, send data to the user via a socket. You can look for alternatives to kue that work directly with memory if you do not want to bloat the technology stack with radish. But I have not seen more or less popular alternatives.

V
Vitaly, 2017-01-15
@vitali1995

Isn't it easier to run Promise for processing in a loop?

V
Vasily Nazarov, 2017-01-16
@vnaz

Read about queues (MQ).
Perhaps an implementation on the database is suitable, but on average it is "more correct" to use a ready-made queue server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question