points by gf000 1 week ago

If the two calls are sequential then simply:

  var x = someFunction()
  someOtherFunction()

If you would have written

  var xTask = SomeFunctionAsync();
  await WaitForSomeOtherFunctionAsync();
  string x = await xTask;

then it would be:

  try (var scope = StructuredTaskScope.open()) {   // JDK 24+ preview feature 
      var x = scope.fork(() -> someFunction());
      scope.fork(() -> waitForSomeOtherFunction());
      scope.join();
      String result = x.get(); // already completed 
  }
troupo 6 days ago

await implies async functions.

Looks like Java's "there is no simpler syntax than plain old synchronous code" is just a lot of extra manual wrangling of stuff

  • gf000 6 days ago

    And the first two lines are an async function as they are, without any special handling.

    They won't block the thread, and you can have millions of them.

    Like it's no accident that c# with their goldfish attention span wanted to ship virtual threads as well next to all their millions of features.

    • troupo 6 days ago

      Strangely enough virtually no materials on the internet show that. Everything is Executors, and Futures, and joins etc.

      • gf000 5 days ago

        Concurrency != parallelism

        I hope you know and understand the difference. Then strangely enough all my examples will make sense.