Package cloud.opencode.base.functional.async


package cloud.opencode.base.functional.async
Async Utilities - Virtual Thread functional utilities 异步工具 - 虚拟线程函数式工具

Provides asynchronous functional utilities leveraging JDK 25's Virtual Threads and Structured Concurrency for efficient parallel execution.

利用 JDK 25 的虚拟线程和结构化并发提供异步函数式工具,实现高效并行执行。

Features | 主要功能:

Usage Examples | 使用示例:

// Async Try execution
CompletableFuture<Try<String>> future = AsyncFunctionUtil.tryAsync(
    () -> httpClient.get(url));

// Parallel execution
List<Try<User>> results = AsyncFunctionUtil.parallel(
    List.of(
        () -> fetchUser(1),
        () -> fetchUser(2),
        () -> fetchUser(3)));

// Structured concurrency - all must succeed
Try<List<User>> users = AsyncFunctionUtil.sequence(suppliers);

// LazyAsync - preheating
LazyAsync<ExpensiveData> lazy = LazyAsync.of(this::computeData);
lazy.preheat();  // Start computing in virtual thread
// ... do other work ...
ExpensiveData data = lazy.get();  // Get result when ready

JDK 25 Features Used | 使用的 JDK 25 特性:

  • Virtual Threads - 虚拟线程
  • Structured Concurrency - 结构化并发
Since:
JDK 25, opencode-base-functional V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Class
    Description
    AsyncFunctionUtil - Virtual Thread based async utilities AsyncFunctionUtil - 基于虚拟线程的异步工具
    Future - Functional wrapper for CompletableFuture Future - CompletableFuture 的函数式包装
    LazyAsync - Lazy asynchronous computation LazyAsync - 惰性异步计算
    Computation states 计算状态