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

They aren't perfectly equivalent because the virtual thread example uses a loop instead of the following (dropping the try/catch):

  // client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
  var response = client.send(request, HttpResponse.BodyHandlers.ofString()); 
  // .thenApply(HttpResponse::body)
  var body = response.body();
  // .thenApply(this::getImageURLs)
  var urls = getImageURLs(body);
  //  .thenCompose(this::getImages)
  var images = getImages(urls);
  // .thenAccept(this::saveImages)
  saveImages(images);
And if it had been written this way it would have been clearer that they are, in fact, equivalent. But generally people don't write like this, they use looping constructs.

Regardless, the important bit is that the parallel/concurrent bit of the async one is that it is cast off into an async system. The following execution steps are, well, steps. Each executed in sequence. Just like the body of the virtual thread example would be executed, but without the cumbersome noise of thenApply and thenCompose and such.



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: