Live data from Hacker News

setBigTimeout

evanhahn.com

101–110 of 129 posts

Re: setBigTimeout

#101
post #25

Earlier quoted context omitted.

I agree it’s not the prettiest, but I had no trouble clicking on “tree” to get to the folder and then “mod.ts” to see the code.

One has still to know that "tree" stands for "source code".

Well it doesn't stand for "source code". It's the tree of directories and files.

Re: setBigTimeout

#102

setTimeout is stranger than you think. We recently had a failed unit test because setTimeout(fn, 1000) triggered at 999ms. That test had ran more than a hundred times before just fine. Till one day it didn't.

setTimeout has no guarantees, and even if it did, your unit tests shouldn't depend on it. Flaky unit tests are a scourge. The top causes of flaky unit tests in my experience: - wall clock time ( and timezones ) - user time ( and timeouts ) - network calls - local I/O These are also, generally speaking, a cause of unnecessarily slow unit tests. If your unit test is waiting 1000ms, then it's taking 1000ms longer than i…

>Fast reliable unit tests are difficult

Not difficult if you build your code (not just the test suite) around scheduling APIs (and queues implementations, etc.) that can be implemented using virtual time instead of CPU/wall clock time (I call that soft vs hard time).

Actually I find it a breeze to create such fast and deterministic unit tests.

Re: setBigTimeout

#104

This makes me love having Go handy. I find working with signals and time based events so much nicer than other languages I use. This is fun, though. JS is a bucket of weird little details like this.

Go timers do have weird little details, in fact one little detail changed recently in 1.23 and broke my code. A third party dependency selects on sending to a channel and time.After(0); before 1.23, due to timer scheduling delay, the first case would always win if the channel has capacity to receive, but since 1.23 the timer scheduling delay is gone and the “timeout” wins half the time. The change is documented at https://go.dev/wiki/Go123Timer but unless you read release notes very carefully (in fact I don’t think the race issue is mentioned in 1.23 release notes proper, only on the separate deep dive which is not linked from release notes) and are intimately familiar with everything that goes into your codebase, you can be unexpectedly bitten by change like this like me.

Re: setBigTimeout

#106
post #74

Earlier quoted context omitted.

This is not a sourcehut problem, it is a github problem. "Tree" is semantically correct.

What? Of course it's a Sourcehut problem. They chose to use that word and could choose to use a better one.

Tree has been used for this kind of thing for decades now.

Re: setBigTimeout

#107

In response to this, I read the spec of setTimeout, bu I couldn't find the part where implementations may have an upper bound. Can someone more familiär with the specs point me in the right direction?

Here’s a deep dive in 6 minutes https://youtu.be/boD0ReK62FI?si=jSXuQn0DHn3riJgd

Just JS being JS: setTimeout(()=>{}, Infinity) executes immediately

Re: setBigTimeout

#109
post #11

Earlier quoted context omitted.

No, it pretty much just does exactly that. const subtractNextDelay = () => { if (typeof remainingDelay === "number") { remainingDelay -= MAX_REAL_DELAY; } else { remainingDelay -= BigInt(MAX_REAL_DELAY); } };

Oh yikes. Yeah; not ideal.

But it appears that it is consistent with setTimeout’s behavior and therefore likely correct in the context it will be used.

At least if your definition of “correct” is “does the thing most similar to the thing I’m extending/replicating”. In fact you might believe it’s a bug to do otherwise, and JS (I’m no expert) doesn’t give a way to run off the event loop anyway (in all implementations). Although I’d be amused to see someone running even a 90 day timer in the browser. :)

I’ve think a very precise timeout would want a different name, to distinguish it from setTimeout’s behavior.

Re: setBigTimeout

#110

The longer the delay, the more likely the process is to crash before the timer completes. Use a scheduler instead.

Correct take. But I also want to point out that this earnest reply is casting "remove curse" on this cursed library.
Post reply on HN