tc39 / proposal-atomics-microwait

Micro waits in JS
http://tc39.es/proposal-atomics-microwait/
Other
49 stars 1 forks source link

microwait/microtask/microsecond and how to communicate who this API is for #4

Closed ptomato closed 7 months ago

ptomato commented 8 months ago

Atomics.microwait is a "power tool" that should be in the language for the few situations where it's needed; most code shouldn't need to use it.

I'd guess that most JS developers in the world don't think of locks and threads at all and have at best only vague ideas about concurrent execution. Microtasks and microseconds are two other timing-related concepts that also start with "micro". It seems plausible that this proposal will be popularly misunderstood as "TC39 is bringing queueMicrotask over from the DOM" or "Atomics.microwait(5) is the same as time.sleep(5e-6) in Python" or some such thing.

I don't have a particular action to suggest, just that it should be considered during stage 2 how to communicate who the API is for and when it should be used.

For inspiration, in Temporal we tried to deal with the "power tool" APIs by giving them non-catchy names like getISOFields(), that weren't likely to be confused with other concepts when they appear in IDE popups.

bakkot commented 8 months ago

This is a good consideration, but FWIW I think that placement on Atomics is already enough to make it clearly not for use in most code.

syg commented 8 months ago

I agree with https://github.com/tc39/proposal-atomics-microwait/issues/4#issuecomment-2043520600, in that everything in Atomics is a power tool, so I don't think a particular method in it needs consideration.

The auto-complete hazard doesn't apply because that's when the same "namespace" (whether a static object or a prototype object) has both common and rare APIs. The Signals proposal is putting the rare ones in a .subtle, which I like and is cute. But it wouldn't help to apply to Atomics because we should put everything in .subtle.

That said, how do you feel about Atomics.pause?

ptomato commented 8 months ago

I don't really have a clear answer to the question about what makes a good name in this situation; wish I did! That said, I do like Atomics.pause because it doesn't risk confusion with microtasks/microseconds.

syg commented 7 months ago

I'm happy with Atomics.pause. That will also mirror the proposed opcode on the Wasm side.