0
\$\begingroup\$

I'm developing a card game server. I want to do this : While server process a turn for players, players have 20 seconds to do something. If players send a request to server within 20 secs, timer will stop and the callback will fire.

I'm doing like this :

self.tables[table.id].currentTimer = setTimeout(function () { callback(); }, 20*1000);

How should I run the callback before delay time exceeded ?

\$\endgroup\$
1
\$\begingroup\$

Just stop the timer and then call the callback yourself.

clearTimeout(self.tables[table.id].currentTimer);
callback();
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.