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 Answer 1

1
\$\begingroup\$

Just stop the timer and then call the callback yourself.

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.