Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can this be done on the runtime level? Zig, if I recall, supports multi-colored functions. Would it be possible to terminate an awaitable early?


Multi-colored? Google doesn't spit out anything meaningful and ChatGPT claims that Zig didn't exist in Sept 2021...


I think in popular parlance the terminology comes from the "What color is your function?" article[0]. The idea is that "normal" and async functions are different colors and they don't mix. When you call an async function from a normal one you make the normal one async, i.e. if it had no color it now takes on the color of the async one, etc.

Zig has a system where calling an async function is actually doable while still leaving the calling function non-async.

0 - https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...


Oh yeah, I know about that. But that is commonly called "colored functions" not "multi colored functions" no? So I thought there was a difference.


Right, colored functions are e.g. async or not async. In Zig, you can write a single function that works as both, which I assume is what multicolored means here.


That doesn't seem to make any sense to me - it should be then called uncolored functions no? Because they all look the same.

But maybe that's what they ment to say.


They're generic over ‘color’ at compile time; the compiler generates code for normal and/or async contexts as necessary.


Right - so to the developer they all look the same, which means they are uncolored. If they are colored it means they look different (e.g. async vs sync).


Zig aims to solve this “problem” by having functions that can be either async or not.


They're (presumably) refering to "colorblind" functions. (Note that "blind" is apt here: the color isn't visible, but functions still have color and will break in subtle ways if you try to use them as if they don't.[0])

Zig's approach is probably a improvement over bare async/await, but pre-javascript languages already had more of a improvement in the form of not having async/await. Implementing async/await at all makes the language worse unless there's a (preferably provably) universally-applicable way for functions to be (explicitly) generic about whether they're async or not.

0: https://gavinhoward.com/2022/04/i-believe-zig-has-function-c...


ChatGPT isn't great for spitting out accurate facts, especially if you just ask once, especially if you don't add additional details and otherwise engineer the prompt, especially if you're asking questions involving digits and numerals, and you especially if small details matter. Zig was definitely far enough along to have multi-colored functions over a year prior to that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: