W
W
Wasya UK2018-10-17 16:43:47
Node.js
Wasya UK, 2018-10-17 16:43:47

What is the correct way to do setInterval in Node?

It is necessary to give a number to clients every 2 seconds. Is it right to do so?

setInterval(() => {
  const bitcoin_price = Math.random() * (6000 - 0) + 0;

  clients.forEach(resolve => {
    resolve(bitcoin_price);
  });

  clients = [];
}, 2000);

P.S. The return must be on the server side.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2018-10-17
@abberati

> Whether simply I do not know correctly so to set the timer
On one request it is possible to answer only once. Google about websocket, there is a completely different technology and the code will be different. But setInterval will be the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question