Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

ASCII a stupid question, you get an EBCDIC answer.


devel / comp.lang.javascript / Re: Coord timed events

SubjectAuthor
* Coord timed eventsAndrew Poulos
`* Re: Coord timed eventsBen Bacarisse
 `* Re: Coord timed eventsAndrew Poulos
  +- Re: Coord timed eventsBen Bacarisse
  `* Re: Coord timed eventsScott Sauyet
   `* Re: Coord timed eventsAndrew Poulos
    `* Re: Coord timed eventsJonas Thörnvall
     `* Re: Coord timed eventsJonas Thörnvall
      `- Re: Coord timed eventsJonas Thörnvall

1
Coord timed events

<h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17101&group=comp.lang.javascript#17101

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!buffer2.nntp.dca1.giganews.com!nntp.westnet.com.au!news.westnet.com.au.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 16 Jun 2021 19:49:56 -0500
Newsgroups: comp.lang.javascript
X-Mozilla-News-Host: news://news.iinet.net.au:119
From: ap_prog@hotmail.com (Andrew Poulos)
Subject: Coord timed events
Date: Thu, 17 Jun 2021 10:49:55 +1000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-AU
Content-Transfer-Encoding: 7bit
Message-ID: <h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au>
Lines: 16
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 27.33.12.58
X-Trace: sv3-q7nRSCIoFEmWyyKI0lp2Pxow9Gfr3pxmAZ0OtlRkoq3NuxWlxfRzrLGDv2HaX+9OhwFQfKp/+8Vnz9k!fxLPKgI0HtDZz9C8elmeqq9ckX57275ktY+MKX5oKHwHiOZV6XujT8F7u/KOmtRpla0zjBUrNERg!D2LWc9N2kMhE3nJzTw==
X-Complaints-To: abuse@westnet.com.au
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 1776
 by: Andrew Poulos - Thu, 17 Jun 2021 00:49 UTC

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.

I was wondering if there's a better way like maybe creating a counter
that runs until the largest/last timing is triggered? In this way I have
only one thing to control should the user navigate to a different page
component.

Or maybe a countdown type timer that counts up to the largest timing?

regards
Andrew Poulos

Re: Coord timed events

<87eed1jo40.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17102&group=comp.lang.javascript#17102

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.javascript
Subject: Re: Coord timed events
Date: Thu, 17 Jun 2021 02:06:55 +0100
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <87eed1jo40.fsf@bsb.me.uk>
References: <h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="dba4e90f2d9a52676a13a099c8050f76";
logging-data="14090"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/n3GcSm22zkxzhCWRjIEsi4Mkki4DdNLI="
Cancel-Lock: sha1:ciUZ1idxtb9QcckxDopig9QJThg=
sha1:oldYL1VoEiaMMH/rvOtWpjajjIs=
X-BSB-Auth: 1.e6d5f332ec286c1e1fa7.20210617020655BST.87eed1jo40.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 17 Jun 2021 01:06 UTC

Andrew Poulos <ap_prog@hotmail.com> 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...

--
Ben.

Re: Coord timed events

<IsOdnRRCc5ZWI1f9nZ2dnUU7-WfNnZ2d@westnet.com.au>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17103&group=comp.lang.javascript#17103

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!nntp.westnet.com.au!news.westnet.com.au.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 16 Jun 2021 22:17:30 -0500
Subject: Re: Coord timed events
Newsgroups: comp.lang.javascript
References: <h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au>
<87eed1jo40.fsf@bsb.me.uk>
From: ap_prog@hotmail.com (Andrew Poulos)
Date: Thu, 17 Jun 2021 13:17:29 +1000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <87eed1jo40.fsf@bsb.me.uk>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-AU
Content-Transfer-Encoding: 7bit
Message-ID: <IsOdnRRCc5ZWI1f9nZ2dnUU7-WfNnZ2d@westnet.com.au>
Lines: 24
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 27.33.12.58
X-Trace: sv3-0LPd2e2noJtXvz5KLYx4M3frQbbffQvteYqaS1BvwHpC5ThTJqtuvU7qE7dVvh45medNJVHBjOAlO2h!LcWkuKP7415lWH/RJ51Asb2VcSsCb4BLbf96xTROUejUPaVz581BXUbDUETR6HXs/4rvAw1UEbbR!ePgPe1fZJWM3DXW+Gw==
X-Complaints-To: abuse@westnet.com.au
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2147
 by: Andrew Poulos - Thu, 17 Jun 2021 03:17 UTC

On 17/06/2021 11:06 am, Ben Bacarisse wrote:
> Andrew Poulos <ap_prog@hotmail.com> 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. I was
looking for a single point to control all of them without multiple
setTimeout.

At some later stage the client might ask for "unlimited" timings and I'd
rather not have lots of setTimeout running at the same time.

Andrew Poulos

Re: Coord timed events

<878s38kd1a.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17105&group=comp.lang.javascript#17105

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (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: <h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au>
<87eed1jo40.fsf@bsb.me.uk>
<IsOdnRRCc5ZWI1f9nZ2dnUU7-WfNnZ2d@westnet.com.au>
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
 by: Ben Bacarisse - Thu, 17 Jun 2021 10:20 UTC

Andrew Poulos <ap_prog@hotmail.com> writes:

> On 17/06/2021 11:06 am, Ben Bacarisse wrote:
>> Andrew Poulos <ap_prog@hotmail.com> 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.

Re: Coord timed events

<b2d2a73f-70c0-4712-a43b-9578754ffe98n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17106&group=comp.lang.javascript#17106

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:622a:150:: with SMTP id v16mr2883983qtw.340.1623961319394; Thu, 17 Jun 2021 13:21:59 -0700 (PDT)
X-Received: by 2002:a9d:c29:: with SMTP id 38mr6430496otr.195.1623961319049; Thu, 17 Jun 2021 13:21:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 17 Jun 2021 13:21:58 -0700 (PDT)
In-Reply-To: <IsOdnRRCc5ZWI1f9nZ2dnUU7-WfNnZ2d@westnet.com.au>
Injection-Info: google-groups.googlegroups.com; posting-host=170.202.22.110; posting-account=jEz2WAoAAABPN6KvjkIr_ZIYJY4YFml9
NNTP-Posting-Host: 170.202.22.110
References: <h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au> <87eed1jo40.fsf@bsb.me.uk> <IsOdnRRCc5ZWI1f9nZ2dnUU7-WfNnZ2d@westnet.com.au>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b2d2a73f-70c0-4712-a43b-9578754ffe98n@googlegroups.com>
Subject: Re: Coord timed events
From: scott@sauyet.com (Scott Sauyet)
Injection-Date: Thu, 17 Jun 2021 20:21:59 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 86
 by: Scott Sauyet - Thu, 17 Jun 2021 20:21 UTC

Andrew Poulos wrote:
> (response from Ben Bacarisse elided)
>> Andrew Poulos wrote:

>>> 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.

> 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. I was
> looking for a single point to control all of them without multiple
> setTimeout.
>
> At some later stage the client might ask for "unlimited" timings and I'd
> rather not have lots of setTimeout running at the same time.

Dozens, hundreds, probably even thousands of `setTimeout` calls will
probably not slow down modern browsers. But it would feel ... uncleanly.

It would be easy enough to run a single `getInterval` timer that when it
runs checks the remaining actions and runs all those whose time is at hand.
You would need to choose a run-time interval short enough to capture the
likely timing differences between your events but long enough not to clog
up the event queue. For events measured in seconds, up to 300, I would
think running every 250 milliseconds might be reasonable.

Here's an implementation:

```
const handler = (periodInMilliseconds) => (events) => {
const start = Date .now ()
let toProcess = events .map (
([fn, delayInSecs]) => ({fn, runTime: start + 1000 * delayInSecs})
)
const interval = setInterval (
() => {
const now = Date .now ()
toProcess .filter (e => e .runTime <= now) .forEach (e => e .fn ())
toProcess = toProcess .filter (e => e .runTime > now)
},
periodInMilliseconds
)
return {
stop: (after = () => {}) => {clearInterval (interval); after ()}
}
} ```

which might be used like this:

```
const {stop} = handler (250) ([
[() => console .log ('A'), 4],
[() => console .log ('B'), 2],
[() => console .log ('C'), 15],
[() => console .log ('D'), 7],
[() => console .log ('E'), 1],
])

setTimeout (() => stop (() => console.log ('completed')), 10000)
```

You call handler passing the period (250ms) and an array of arrays,
each containing a function to run and the delay in seconds. You get
back a `stop` function which will terminate the running (and call
an optional callback afterward if you like.)

At the start, the functions are paired with the time they should run.

At each interval, we calculate the current time and, if checks each
function. If it is now due, we run the function and remove it from
the `toProcess` list.

The example above would log `E` after one second, `B` after two
seconds, `A` after four seconds, `D` after seven seconds. But
because we call `stop` after ten seconds, the events are stopped
before we reach `C`. Note that our optional callback will log
`completed` at that time.

This is a fairly naive version. We might want to improve it to clear
the interval when the queue is empty. We might want to add an explicit
`start` parallel to `stop`, to start the queue when we choose. Or we
might want to specify the `stop` callback initially with the period.
And many other improvements are certainly possible. But it's a decent
start at the problem.
..

-- Scott

Re: Coord timed events

<g6adnWbLO69rbVb9nZ2dnUU7-UHNnZ2d@westnet.com.au>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17108&group=comp.lang.javascript#17108

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!nntp.westnet.com.au!news.westnet.com.au.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 17 Jun 2021 20:03:50 -0500
Subject: Re: Coord timed events
Newsgroups: comp.lang.javascript
References: <h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au>
<87eed1jo40.fsf@bsb.me.uk> <IsOdnRRCc5ZWI1f9nZ2dnUU7-WfNnZ2d@westnet.com.au>
<b2d2a73f-70c0-4712-a43b-9578754ffe98n@googlegroups.com>
From: ap_prog@hotmail.com (Andrew Poulos)
Date: Fri, 18 Jun 2021 11:03:49 +1000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <b2d2a73f-70c0-4712-a43b-9578754ffe98n@googlegroups.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-AU
Content-Transfer-Encoding: 7bit
Message-ID: <g6adnWbLO69rbVb9nZ2dnUU7-UHNnZ2d@westnet.com.au>
Lines: 90
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 27.33.12.58
X-Trace: sv3-Jye51xf29SHmZv5ZFi1qmaKALhE+nn4eFSykmAk8etdtckNqGXxznipUctPCX60ffv21wdoJDVVXLKt!YvhtrVmTy2GrO+X+JudLnFw0jevMfpL15c2R7MCGdHGaS8fWMRnuUjRleRmDdLxZIEaMnd8Oj+C4!MFqI7b++2wtbxzcWWw==
X-Complaints-To: abuse@westnet.com.au
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 4904
 by: Andrew Poulos - Fri, 18 Jun 2021 01:03 UTC

On 18/06/2021 6:21 am, Scott Sauyet wrote:
> Andrew Poulos wrote:
>> (response from Ben Bacarisse elided)
>>> Andrew Poulos wrote:
>
>>>> 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.
>
>> 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. I was
>> looking for a single point to control all of them without multiple
>> setTimeout.
>>
>> At some later stage the client might ask for "unlimited" timings and I'd
>> rather not have lots of setTimeout running at the same time.
>
> Dozens, hundreds, probably even thousands of `setTimeout` calls will
> probably not slow down modern browsers. But it would feel ... uncleanly.
>
> It would be easy enough to run a single `getInterval` timer that when it
> runs checks the remaining actions and runs all those whose time is at hand.
> You would need to choose a run-time interval short enough to capture the
> likely timing differences between your events but long enough not to clog
> up the event queue. For events measured in seconds, up to 300, I would
> think running every 250 milliseconds might be reasonable.
>
> Here's an implementation:
>
> ```
> const handler = (periodInMilliseconds) => (events) => {
> const start = Date .now ()
> let toProcess = events .map (
> ([fn, delayInSecs]) => ({fn, runTime: start + 1000 * delayInSecs})
> )
> const interval = setInterval (
> () => {
> const now = Date .now ()
> toProcess .filter (e => e .runTime <= now) .forEach (e => e .fn ())
> toProcess = toProcess .filter (e => e .runTime > now)
> },
> periodInMilliseconds
> )
> return {
> stop: (after = () => {}) => {clearInterval (interval); after ()}
> }
> }
> ```
>
> which might be used like this:
>
> ```
> const {stop} = handler (250) ([
> [() => console .log ('A'), 4],
> [() => console .log ('B'), 2],
> [() => console .log ('C'), 15],
> [() => console .log ('D'), 7],
> [() => console .log ('E'), 1],
> ])
>
> setTimeout (() => stop (() => console.log ('completed')), 10000)
> ```
>
> You call handler passing the period (250ms) and an array of arrays,
> each containing a function to run and the delay in seconds. You get
> back a `stop` function which will terminate the running (and call
> an optional callback afterward if you like.)
>
> At the start, the functions are paired with the time they should run.
>
> At each interval, we calculate the current time and, if checks each
> function. If it is now due, we run the function and remove it from
> the `toProcess` list.
>
> The example above would log `E` after one second, `B` after two
> seconds, `A` after four seconds, `D` after seven seconds. But
> because we call `stop` after ten seconds, the events are stopped
> before we reach `C`. Note that our optional callback will log
> `completed` at that time.
>
> This is a fairly naive version. We might want to improve it to clear
> the interval when the queue is empty. We might want to add an explicit
> `start` parallel to `stop`, to start the queue when we choose. Or we
> might want to specify the `stop` callback initially with the period.
> And many other improvements are certainly possible. But it's a decent
> start at the problem.

Thanks. It's given me something I can work with.

Andrew Poulos

Re: Coord timed events

<e1eb60e7-10a6-4f47-b274-dd62625cbc7fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17118&group=comp.lang.javascript#17118

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:6214:19e3:: with SMTP id q3mr18346441qvc.33.1624257633196;
Sun, 20 Jun 2021 23:40:33 -0700 (PDT)
X-Received: by 2002:a05:6808:15a7:: with SMTP id t39mr15653548oiw.176.1624257632944;
Sun, 20 Jun 2021 23:40:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Sun, 20 Jun 2021 23:40:32 -0700 (PDT)
In-Reply-To: <g6adnWbLO69rbVb9nZ2dnUU7-UHNnZ2d@westnet.com.au>
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.163.187; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.163.187
References: <h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au>
<87eed1jo40.fsf@bsb.me.uk> <IsOdnRRCc5ZWI1f9nZ2dnUU7-WfNnZ2d@westnet.com.au>
<b2d2a73f-70c0-4712-a43b-9578754ffe98n@googlegroups.com> <g6adnWbLO69rbVb9nZ2dnUU7-UHNnZ2d@westnet.com.au>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e1eb60e7-10a6-4f47-b274-dd62625cbc7fn@googlegroups.com>
Subject: Re: Coord timed events
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Mon, 21 Jun 2021 06:40:33 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Jonas Thörnvall - Mon, 21 Jun 2021 06:40 UTC

fredag 18 juni 2021 kl. 03:04:02 UTC+2 skrev Andrew Poulos:
> On 18/06/2021 6:21 am, Scott Sauyet wrote:
> > Andrew Poulos wrote:
> >> (response from Ben Bacarisse elided)
> >>> Andrew Poulos wrote:
> >
> >>>> 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.
> >
> >> 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. I was
> >> looking for a single point to control all of them without multiple
> >> setTimeout.
> >>
> >> At some later stage the client might ask for "unlimited" timings and I'd
> >> rather not have lots of setTimeout running at the same time.
> >
> > Dozens, hundreds, probably even thousands of `setTimeout` calls will
> > probably not slow down modern browsers. But it would feel ... uncleanly.
> >
> > It would be easy enough to run a single `getInterval` timer that when it
> > runs checks the remaining actions and runs all those whose time is at hand.
> > You would need to choose a run-time interval short enough to capture the
> > likely timing differences between your events but long enough not to clog
> > up the event queue. For events measured in seconds, up to 300, I would
> > think running every 250 milliseconds might be reasonable.
> >
> > Here's an implementation:
> >
> > ```
> > const handler = (periodInMilliseconds) => (events) => {
> > const start = Date .now ()
> > let toProcess = events .map (
> > ([fn, delayInSecs]) => ({fn, runTime: start + 1000 * delayInSecs})
> > )
> > const interval = setInterval (
> > () => {
> > const now = Date .now ()
> > toProcess .filter (e => e .runTime <= now) .forEach (e => e .fn ())
> > toProcess = toProcess .filter (e => e .runTime > now)
> > },
> > periodInMilliseconds
> > )
> > return {
> > stop: (after = () => {}) => {clearInterval (interval); after ()}
> > }
> > }
> > ```
> >
> > which might be used like this:
> >
> > ```
> > const {stop} = handler (250) ([
> > [() => console .log ('A'), 4],
> > [() => console .log ('B'), 2],
> > [() => console .log ('C'), 15],
> > [() => console .log ('D'), 7],
> > [() => console .log ('E'), 1],
> > ])
> >
> > setTimeout (() => stop (() => console.log ('completed')), 10000)
> > ```
> >
> > You call handler passing the period (250ms) and an array of arrays,
> > each containing a function to run and the delay in seconds. You get
> > back a `stop` function which will terminate the running (and call
> > an optional callback afterward if you like.)
> >
> > At the start, the functions are paired with the time they should run.
> >
> > At each interval, we calculate the current time and, if checks each
> > function. If it is now due, we run the function and remove it from
> > the `toProcess` list.
> >
> > The example above would log `E` after one second, `B` after two
> > seconds, `A` after four seconds, `D` after seven seconds. But
> > because we call `stop` after ten seconds, the events are stopped
> > before we reach `C`. Note that our optional callback will log
> > `completed` at that time.
> >
> > This is a fairly naive version. We might want to improve it to clear
> > the interval when the queue is empty. We might want to add an explicit
> > `start` parallel to `stop`, to start the queue when we choose. Or we
> > might want to specify the `stop` callback initially with the period.
> > And many other improvements are certainly possible. But it's a decent
> > start at the problem.
> Thanks. It's given me something I can work with.
>
> Andrew Poulos

Here is how i shedule timed events.

function startIT(){
playPos=0;
stopRec=setInterval(doIT,5);
}

function doIT(){
//Play end is set in scrollbar
REALTIME=performance.now()-browserLoadTIME;
while(REALTIME>schedTime){
//Do something
schedTime=copyEv[playPos]+schedTime;
playPos++;
}
}

Re: Coord timed events

<74c0bad6-3836-405d-8f1f-e261b27efaf3n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17119&group=comp.lang.javascript#17119

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:6214:252e:: with SMTP id gg14mr18197982qvb.55.1624258120933;
Sun, 20 Jun 2021 23:48:40 -0700 (PDT)
X-Received: by 2002:a4a:5886:: with SMTP id f128mr19521881oob.48.1624258120697;
Sun, 20 Jun 2021 23:48:40 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Sun, 20 Jun 2021 23:48:40 -0700 (PDT)
In-Reply-To: <e1eb60e7-10a6-4f47-b274-dd62625cbc7fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.163.187; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.163.187
References: <h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au>
<87eed1jo40.fsf@bsb.me.uk> <IsOdnRRCc5ZWI1f9nZ2dnUU7-WfNnZ2d@westnet.com.au>
<b2d2a73f-70c0-4712-a43b-9578754ffe98n@googlegroups.com> <g6adnWbLO69rbVb9nZ2dnUU7-UHNnZ2d@westnet.com.au>
<e1eb60e7-10a6-4f47-b274-dd62625cbc7fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <74c0bad6-3836-405d-8f1f-e261b27efaf3n@googlegroups.com>
Subject: Re: Coord timed events
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Mon, 21 Jun 2021 06:48:40 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Jonas Thörnvall - Mon, 21 Jun 2021 06:48 UTC

måndag 21 juni 2021 kl. 08:40:37 UTC+2 skrev Jonas Thörnvall:
> fredag 18 juni 2021 kl. 03:04:02 UTC+2 skrev Andrew Poulos:
> > On 18/06/2021 6:21 am, Scott Sauyet wrote:
> > > Andrew Poulos wrote:
> > >> (response from Ben Bacarisse elided)
> > >>> Andrew Poulos wrote:
> > >
> > >>>> 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.
> > >
> > >> 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. I was
> > >> looking for a single point to control all of them without multiple
> > >> setTimeout.
> > >>
> > >> At some later stage the client might ask for "unlimited" timings and I'd
> > >> rather not have lots of setTimeout running at the same time.
> > >
> > > Dozens, hundreds, probably even thousands of `setTimeout` calls will
> > > probably not slow down modern browsers. But it would feel ... uncleanly.
> > >
> > > It would be easy enough to run a single `getInterval` timer that when it
> > > runs checks the remaining actions and runs all those whose time is at hand.
> > > You would need to choose a run-time interval short enough to capture the
> > > likely timing differences between your events but long enough not to clog
> > > up the event queue. For events measured in seconds, up to 300, I would
> > > think running every 250 milliseconds might be reasonable.
> > >
> > > Here's an implementation:
> > >
> > > ```
> > > const handler = (periodInMilliseconds) => (events) => {
> > > const start = Date .now ()
> > > let toProcess = events .map (
> > > ([fn, delayInSecs]) => ({fn, runTime: start + 1000 * delayInSecs})
> > > )
> > > const interval = setInterval (
> > > () => {
> > > const now = Date .now ()
> > > toProcess .filter (e => e .runTime <= now) .forEach (e => e .fn ())
> > > toProcess = toProcess .filter (e => e .runTime > now)
> > > },
> > > periodInMilliseconds
> > > )
> > > return {
> > > stop: (after = () => {}) => {clearInterval (interval); after ()}
> > > }
> > > }
> > > ```
> > >
> > > which might be used like this:
> > >
> > > ```
> > > const {stop} = handler (250) ([
> > > [() => console .log ('A'), 4],
> > > [() => console .log ('B'), 2],
> > > [() => console .log ('C'), 15],
> > > [() => console .log ('D'), 7],
> > > [() => console .log ('E'), 1],
> > > ])
> > >
> > > setTimeout (() => stop (() => console.log ('completed')), 10000)
> > > ```
> > >
> > > You call handler passing the period (250ms) and an array of arrays,
> > > each containing a function to run and the delay in seconds. You get
> > > back a `stop` function which will terminate the running (and call
> > > an optional callback afterward if you like.)
> > >
> > > At the start, the functions are paired with the time they should run.
> > >
> > > At each interval, we calculate the current time and, if checks each
> > > function. If it is now due, we run the function and remove it from
> > > the `toProcess` list.
> > >
> > > The example above would log `E` after one second, `B` after two
> > > seconds, `A` after four seconds, `D` after seven seconds. But
> > > because we call `stop` after ten seconds, the events are stopped
> > > before we reach `C`. Note that our optional callback will log
> > > `completed` at that time.
> > >
> > > This is a fairly naive version. We might want to improve it to clear
> > > the interval when the queue is empty. We might want to add an explicit
> > > `start` parallel to `stop`, to start the queue when we choose. Or we
> > > might want to specify the `stop` callback initially with the period.
> > > And many other improvements are certainly possible. But it's a decent
> > > start at the problem.
> > Thanks. It's given me something I can work with.
> >
> > Andrew Poulos
> Here is how i shedule timed events.
>
>
> function startIT(){
> playPos=0;
> stopRec=setInterval(doIT,5);
> }
>
> function doIT(){
> //Play end is set in scrollbar
> REALTIME=performance.now()-browserLoadTIME;
> while(REALTIME>schedTime){
> //Do something
> schedTime=copyEv[playPos]+schedTime;
> playPos++;
> }
> }

As you can see my timings rest in copyEV and are relative copyEV timings.
If the copyEV timings are relative zero.....

Then you of course have some event performed at do something....

function startIT(){
playPos=0;
stopRec=setInterval(doIT,5);
}
function doIT(){
//Play end is set in scrollbar
REALTIME=performance.now()-browserLoadTIME;
while(REALTIME>schedTime){
//Do something
schedTime=copyEv[playPos];
playPos++;
}
}

Re: Coord timed events

<ff23d8c1-d4a1-4037-90b2-da7df8ce37b1n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17121&group=comp.lang.javascript#17121

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a0c:d68f:: with SMTP id k15mr1441811qvi.14.1624475514601;
Wed, 23 Jun 2021 12:11:54 -0700 (PDT)
X-Received: by 2002:a05:6830:40b4:: with SMTP id x52mr1220629ott.117.1624475514236;
Wed, 23 Jun 2021 12:11:54 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Wed, 23 Jun 2021 12:11:53 -0700 (PDT)
In-Reply-To: <74c0bad6-3836-405d-8f1f-e261b27efaf3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.217.163.187; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW
NNTP-Posting-Host: 84.217.163.187
References: <h_KdnVLOH6-pAVf9nZ2dnUU7-efNnZ2d@westnet.com.au>
<87eed1jo40.fsf@bsb.me.uk> <IsOdnRRCc5ZWI1f9nZ2dnUU7-WfNnZ2d@westnet.com.au>
<b2d2a73f-70c0-4712-a43b-9578754ffe98n@googlegroups.com> <g6adnWbLO69rbVb9nZ2dnUU7-UHNnZ2d@westnet.com.au>
<e1eb60e7-10a6-4f47-b274-dd62625cbc7fn@googlegroups.com> <74c0bad6-3836-405d-8f1f-e261b27efaf3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ff23d8c1-d4a1-4037-90b2-da7df8ce37b1n@googlegroups.com>
Subject: Re: Coord timed events
From: jonas.thornvall@gmail.com (Jonas Thörnvall)
Injection-Date: Wed, 23 Jun 2021 19:11:54 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 159
 by: Jonas Thörnvall - Wed, 23 Jun 2021 19:11 UTC

måndag 21 juni 2021 kl. 08:48:45 UTC+2 skrev Jonas Thörnvall:
> måndag 21 juni 2021 kl. 08:40:37 UTC+2 skrev Jonas Thörnvall:
> > fredag 18 juni 2021 kl. 03:04:02 UTC+2 skrev Andrew Poulos:
> > > On 18/06/2021 6:21 am, Scott Sauyet wrote:
> > > > Andrew Poulos wrote:
> > > >> (response from Ben Bacarisse elided)
> > > >>> Andrew Poulos wrote:
> > > >
> > > >>>> 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.
> > > >
> > > >> 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. I was
> > > >> looking for a single point to control all of them without multiple
> > > >> setTimeout.
> > > >>
> > > >> At some later stage the client might ask for "unlimited" timings and I'd
> > > >> rather not have lots of setTimeout running at the same time.
> > > >
> > > > Dozens, hundreds, probably even thousands of `setTimeout` calls will
> > > > probably not slow down modern browsers. But it would feel ... uncleanly.
> > > >
> > > > It would be easy enough to run a single `getInterval` timer that when it
> > > > runs checks the remaining actions and runs all those whose time is at hand.
> > > > You would need to choose a run-time interval short enough to capture the
> > > > likely timing differences between your events but long enough not to clog
> > > > up the event queue. For events measured in seconds, up to 300, I would
> > > > think running every 250 milliseconds might be reasonable.
> > > >
> > > > Here's an implementation:
> > > >
> > > > ```
> > > > const handler = (periodInMilliseconds) => (events) => {
> > > > const start = Date .now ()
> > > > let toProcess = events .map (
> > > > ([fn, delayInSecs]) => ({fn, runTime: start + 1000 * delayInSecs})
> > > > )
> > > > const interval = setInterval (
> > > > () => {
> > > > const now = Date .now ()
> > > > toProcess .filter (e => e .runTime <= now) .forEach (e => e .fn ())
> > > > toProcess = toProcess .filter (e => e .runTime > now)
> > > > },
> > > > periodInMilliseconds
> > > > )
> > > > return {
> > > > stop: (after = () => {}) => {clearInterval (interval); after ()}
> > > > }
> > > > }
> > > > ```
> > > >
> > > > which might be used like this:
> > > >
> > > > ```
> > > > const {stop} = handler (250) ([
> > > > [() => console .log ('A'), 4],
> > > > [() => console .log ('B'), 2],
> > > > [() => console .log ('C'), 15],
> > > > [() => console .log ('D'), 7],
> > > > [() => console .log ('E'), 1],
> > > > ])
> > > >
> > > > setTimeout (() => stop (() => console.log ('completed')), 10000)
> > > > ```
> > > >
> > > > You call handler passing the period (250ms) and an array of arrays,
> > > > each containing a function to run and the delay in seconds. You get
> > > > back a `stop` function which will terminate the running (and call
> > > > an optional callback afterward if you like.)
> > > >
> > > > At the start, the functions are paired with the time they should run.
> > > >
> > > > At each interval, we calculate the current time and, if checks each
> > > > function. If it is now due, we run the function and remove it from
> > > > the `toProcess` list.
> > > >
> > > > The example above would log `E` after one second, `B` after two
> > > > seconds, `A` after four seconds, `D` after seven seconds. But
> > > > because we call `stop` after ten seconds, the events are stopped
> > > > before we reach `C`. Note that our optional callback will log
> > > > `completed` at that time.
> > > >
> > > > This is a fairly naive version. We might want to improve it to clear
> > > > the interval when the queue is empty. We might want to add an explicit
> > > > `start` parallel to `stop`, to start the queue when we choose. Or we
> > > > might want to specify the `stop` callback initially with the period..
> > > > And many other improvements are certainly possible. But it's a decent
> > > > start at the problem.
> > > Thanks. It's given me something I can work with.
> > >
> > > Andrew Poulos
> > Here is how i shedule timed events.
> >
> >
> > function startIT(){
> > playPos=0;
> > stopRec=setInterval(doIT,5);
> > }
> >
> > function doIT(){
> > //Play end is set in scrollbar
> > REALTIME=performance.now()-browserLoadTIME;
> > while(REALTIME>schedTime){
> > //Do something
> > schedTime=copyEv[playPos]+schedTime;
> > playPos++;
> > }
> > }
> As you can see my timings rest in copyEV and are relative copyEV timings.
> If the copyEV timings are relative zero.....
>
> Then you of course have some event performed at do something....
> function startIT(){
> playPos=0;
> stopRec=setInterval(doIT,5);
> }
>
> function doIT(){
> //Play end is set in scrollbar
> REALTIME=performance.now()-browserLoadTIME;
> while(REALTIME>schedTime){
> //Do something
> schedTime=copyEv[playPos];
> playPos++;
> }
> }
Well you should init with.
REALTIME=performance.now()-browserLoadTIME;
shedTime=copyEv[0]
And end with
if(copyEv[copyEv.length]<REALTIME){clearInterval (stopRec); }


devel / comp.lang.javascript / Re: Coord timed events

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor