How to have client initialize timer which runs independent of the client?

I need to be able to start a timer (timer will send data to mongo) when a client clicks a button. The timer needs to continue counting down even if the client disconnects. Would anyone be able to tell me a technique for doing that?

You may want to use a job queue to manage this, something like

User clicks button -> Call meteor method -> (server) add a job that executes your function at a given interval.

Are you sure you need to “physically” count down though? Depending on your use case, you could just save the end time , and execute a function at that time.

Thanks jorgeer.
How would I code executing a function at the end time?

Another job queue has the option of delaying a job, so that might be what you want.

The example uses a client and server, but you could easily put the client code in the method call, or just create the job on the client if you want.

Note that I haven’t used these packages myself, so I can’t help you with the details :confused:

Thanks again, but I think i might be looking for the wrong thing. i just want to make an interface for setting and viewing live time and score from a basketball game.

If it’s just a single job or a small handful, then merely have the server submit a cron job.

If there’s an unknown number of jobs from multiple users then the data structure you want is called a priority queue.

Different implementations have different insert/peek/removal times. I’m sure there are javascript implementations on npm of most. Just find the one where the characteristics suit your needs.