Hacker News new | past | comments | ask | show | jobs | submit login

Seems fine but I'm confused by the async/await hate. At least in C# it seems to me thee is already a superset of Loom through async/await.

    Thread.startVirtualThread(() -> {});
Starts a new virtual thread that will run a synchronous method. Ok cool. C# already has:

    Task.Run(()=>{})
This will run synchronously on the shared thread pool. Tasks are futures and can return objects. Same as the Loom proposal.

Optionally you can decide to opt into the await unboxing sugar by adding async to your method signature. There's arguably some double dipping with the async keyword on a method. It allows the await keyword to be used inside the method but also forces the caller into a different calling style. You can argue this shows API intent for cooperative threading. That said, you can still use async and sync interchangeably.

The syntax seems very similar to me.

Is there something else going on in Loom that I'm missing? Is it a matter of how the virtual threads are scheduled/preempted vs how other languages with async/await schedule their tasks?




Maybe I don't understand correctly what your saying but "Task.Run" just schedules something on a normal (kernel) thread by using a common thread pool. The Java equivelant is probably "CompletableFuture.runAsync" which does the same thing.

Loom with "Thread.startVirtualThread" will run something on a userland / green thread (ie. not a kernel thread so no context switching and blocking it "costs" practically nothing). async-await is actually a subset of wat Loom does in the sense that Loom allows for far more then just async-await. Most of the "hate" for async-await is probably because it leads to the "what color is your function" [1] problem.

[1] https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...


The point is that you don't have to write code in a different way if you want to avoid blocking an OS thread on IO operation.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: