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

async/await allows you to do multiple things in parallel. I don't see how you can do that in the virtual threading model

When comparing to JS, it is the other way around. Unless you are talking about IO bound tasks only where nodejs delegates to a thread pool (libuv).



With virtual threads, you need to write fork/join code to do two subtasks. With async await, you call two async functions and await them. So the virtual threading model ends up requiring something that looks like a worse version of async await to me.


  t1 = async(Task1)
  t2 = async(Task2)
  await t1
  await t2

  t1 = fork(Task1)
  t2 = fork(Task2)
  t1.join()
  t2.join()
What's the difference?


If Java adds some nice standardized helpers like this, they will look equivalent. The current proposal is not this clean but that doesn't mean it won't be possible. The key difference is that async/await implies cooperative multitasking. Nothing else happens on the thread until you call await. I find that an easier model to think about, and I opt into multithreading when I need it.

Anyway Rust does this roughly using roughly the syntax you described (except no need to call "fork"). Languages that use async/await do not require you to say "async" at the call site.


I was using `async` as shorthand for "whatever it takes in a particular async implementation to launch an asynchronous task". Here's an example that more or less mirrors what I showed there:

  async def main():
      task1 = asyncio.create_task(
          say_after(1, 'hello'))

      task2 = asyncio.create_task(
          say_after(2, 'world'))

      print(f"started at {time.strftime('%X')}")

      # Wait until both tasks are completed (should take
      # around 2 seconds.)
      await task1
      await task2

      print(f"finished at {time.strftime('%X')}")
https://docs.python.org/3/library/asyncio-task.html

It was a response to a particular thing you said, but I didn't quote because I thought it was obvious (my bad):

> With virtual threads, you need to write fork/join code to do two subtasks. With async await, you call two async functions and await them.

fork/join and async(for you: "whatever it takes in a particular async implementation to launch an asynchronous task")/await have the same pattern (if you need the synchronization point). That example above is a fork/join pattern but without the words "fork" and "join".


> Languages that use async/await do not require you to say "async" at the call site.

Nope, but if you start calling an async function from within a non-async function, then that function now has to become async, and all of the callers of that function have to become async. This isn't a problem with the green threads approach.


In Python you won't get any concurrency by calling two async functions then awaiting each of them, but in Javascript you will.




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

Search: