Answer the question
In order to leave comments, you need to log in
How to emit from node.js through socket.io data from the response at intervals?
I need to make a "movie" (by "movie" I mean changing pages every N seconds) using JS.
I have an array of objects in node.js, using socket.io I want to emit (emit) the content of these objects every N seconds in React.
There is such an API endpoint:
router.get("/start/:handle", (req, res) => {
Game
.findOne({ url: req.params.handle })
.then(game => {
let questionList = [];
game.blocks.map(block => {
block.questions.map(question => {
questionList.push(question)
})
})
questionList.map(question => {
return setInterval(
res.status(200).send(question)
, 5000);
})
})
.catch(err => console.log("start game, err =>", err))
})
Answer the question
In order to leave comments, you need to log in
It probably needs to be done in a different way. But I don't know how to do it
setInterval(() => {
foo(bar);
}, duration);
const interval = setInterval(() => {
foo(bar);
if (someCondition()) {
clearInterval(interval);
}
}, duration);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question