Path: csiph.com!news.swapon.de!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Coord timed events Date: Thu, 17 Jun 2021 11:20:49 +0100 Organization: A noiseless patient Spider Lines: 28 Message-ID: <878s38kd1a.fsf@bsb.me.uk> References: <87eed1jo40.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="dba4e90f2d9a52676a13a099c8050f76"; logging-data="31400"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vn8Be/ZfsFDn2x2BnwRVmxplfnjfSFcg=" Cancel-Lock: sha1:y2QJPrHaf4vUMJlbnv9GLHqdkrw= sha1:bnmie54IC9UVu24UyQfZ9V5uHmo= X-BSB-Auth: 1.21fc4342472c63354cff.20210617112049BST.878s38kd1a.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:40223 Andrew Poulos writes: > On 17/06/2021 11:06 am, Ben Bacarisse wrote: >> Andrew Poulos writes: >> >>> I need to trigger up to 12 "events" with timings a user sets. The >>> timings (in seconds) could be anything from 0 to, say, 300. >>> >>> One way I though to handle them was to: put the timings into an array, >>> sort the array (from lowest to highest), loop over the array and call >>> setTimeout on each one. >> Hmm... Why not just call setTimeout without sorting them? I must be >> missing some key part of the problem... > > If I have 12 setTimeout waiting to happen and the user gives focus to > a different "component" I'll need to clear all the setTimeout. There's no way someone could know that from your original question! That's why I said I must be missing something. You have other constraints -- either imposed by previous design decisions or just from how you want to do things -- that make the obvious solution unattractive. If you could list the constraints, or at least say what it is you are actually doing, you might get some helpful suggestions. -- Ben.