Answer the question
In order to leave comments, you need to log in
How to implement GET request timeout for leader election?
I'm trying to implement the leader Election algorithm for educational purposes.
Here is the TK https://github.com/peterservice-rnd/new-job/blob/m...
Inside the function that starts the election, there is a section of code in which you need to set a timeout for waiting for
a GET request for the route. I don't send requests, I wait for requests from other nodes.
Something like
router.get('/IAMTHEKING/:id', setLeaderId);
...
const setLeaderAnswerTimeout = new Promise((resolve, reject) => {
timeoutId = setTimeout(() => reject('leaderAnswer timeout'), process.env.CHECK_PERIOD);
});
await Promise.race([setLeaderAnswerTimeout, waitLeaderAnswer]);
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question