6
Networking i/o with virtual threads - under the hood – Inside.java (inside.java)
koji 積分 1
List<URLData> retrieveURLs(URL... urls) throws Exception {
  try (var executor = Executors.newVirtualThreadExecutor()) {
    var tasks = Arrays.stream(urls)
            .map(url -> (Callable<URLData>)() -> getURL(url))
            .toList();
    return executor.submit(tasks)
            .filter(Future::isCompletedNormally)
            .map(Future::join)
            .toList();
  }
}

乍看想說isCompletedNormally會true嗎,結果這是新API然後 submit(java.util.Collection)1

Returns:
    stream of completed Futures

這 code review 沒看過的會搞不懂吧