Java 27 and 26: runnable demos and captured output for every JEP, plus version lanes
Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B38FGKKam5SCGgwgduVAh3
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import java.util.concurrent.StructuredTaskScope;
|
||||
|
||||
/**
|
||||
* The same "first result wins" example as StructuredHub, with the factory method under its Java 26 / 27 name:
|
||||
* anySuccessfulResultOrThrow() (25) became anySuccessfulOrThrow() (26 and 27). Still a preview API.
|
||||
* Chapter: docs/14-lanes-21-to-25.md
|
||||
*/
|
||||
public class StructuredHubNew {
|
||||
static String firstSuccess() throws Exception {
|
||||
try (var scope = StructuredTaskScope.open(StructuredTaskScope.Joiner.<String>anySuccessfulOrThrow())) {
|
||||
scope.fork(() -> { Thread.sleep(200); return "slow"; });
|
||||
scope.fork(() -> "fast");
|
||||
return scope.join();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("java.version = " + System.getProperty("java.version"));
|
||||
Check.that(firstSuccess().equals("fast"), "anySuccessfulOrThrow(): the first result wins");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user