You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2026/03/22 14:35:23 UTC
(groovy) branch GROOVY-9381_3 updated: GROOVY-9381: rename `Channel` to `AsyncChannel`
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-9381_3
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY-9381_3 by this push:
new 378a7a4de8 GROOVY-9381: rename `Channel` to `AsyncChannel`
378a7a4de8 is described below
commit 378a7a4de8405a198f863c06a77ec91d74ae7af4
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Mar 22 23:35:09 2026 +0900
GROOVY-9381: rename `Channel` to `AsyncChannel`
---
.../concurrent/{Channel.java => AsyncChannel.java} | 16 +++----
src/main/java/groovy/concurrent/AsyncStream.java | 2 +-
src/main/java/groovy/concurrent/Awaitable.java | 4 +-
.../concurrent/AwaitableAdapterRegistry.java | 6 +--
.../groovy/concurrent/ChannelClosedException.java | 2 +-
.../apache/groovy/runtime/async/AsyncSupport.java | 10 ++--
src/spec/doc/core-async-await.adoc | 22 ++++-----
src/spec/test/AsyncAwaitSpecTest.groovy | 4 +-
.../codehaus/groovy/transform/AsyncApiTest.groovy | 6 +--
.../transform/AsyncContextChannelTest.groovy | 54 +++++++++++-----------
10 files changed, 63 insertions(+), 63 deletions(-)
diff --git a/src/main/java/groovy/concurrent/Channel.java b/src/main/java/groovy/concurrent/AsyncChannel.java
similarity index 96%
rename from src/main/java/groovy/concurrent/Channel.java
rename to src/main/java/groovy/concurrent/AsyncChannel.java
index 63e3dcfb9d..ea9a020903 100644
--- a/src/main/java/groovy/concurrent/Channel.java
+++ b/src/main/java/groovy/concurrent/AsyncChannel.java
@@ -35,7 +35,7 @@ import java.util.concurrent.locks.ReentrantLock;
* buffered until the channel fills, after which senders wait until a
* receiver makes room.
* <p>
- * Channel operations return {@link Awaitable} values so they compose
+ * AsyncChannel operations return {@link Awaitable} values so they compose
* naturally with Groovy's {@code await} and {@link Awaitable#any(Object...)}
* APIs.
* <p>
@@ -57,7 +57,7 @@ import java.util.concurrent.locks.ReentrantLock;
* @param <T> the payload type
* @since 6.0.0
*/
-public final class Channel<T> {
+public final class AsyncChannel<T> {
private final ReentrantLock lock = new ReentrantLock(true);
private final Deque<T> buffer = new ArrayDeque<>();
@@ -70,7 +70,7 @@ public final class Channel<T> {
/**
* Creates an unbuffered channel.
*/
- public Channel() {
+ public AsyncChannel() {
this(0);
}
@@ -79,7 +79,7 @@ public final class Channel<T> {
*
* @param capacity the buffer capacity; must not be negative
*/
- public Channel(int capacity) {
+ public AsyncChannel(int capacity) {
if (capacity < 0) {
throw new IllegalArgumentException("channel capacity must not be negative: " + capacity);
}
@@ -271,7 +271,7 @@ public final class Channel<T> {
public String toString() {
lock.lock();
try {
- return "Channel{capacity=" + capacity
+ return "AsyncChannel{capacity=" + capacity
+ ", buffered=" + buffer.size()
+ ", waitingSenders=" + waitingSenders.size()
+ ", waitingReceivers=" + waitingReceivers.size()
@@ -370,16 +370,16 @@ public final class Channel<T> {
/**
* Read-only {@link AsyncStream} view over a channel.
* <p>
- * Each {@link #moveNext()} call issues a {@link Channel#receive()};
+ * Each {@link #moveNext()} call issues a {@link AsyncChannel#receive()};
* {@link ChannelClosedException} is translated to end-of-stream
* ({@code false}). The stream does not own the channel, so its
* {@link #close()} is a no-op.
*/
private static final class ChannelAsyncStream<T> implements AsyncStream<T> {
- private final Channel<T> channel;
+ private final AsyncChannel<T> channel;
private volatile T current;
- ChannelAsyncStream(Channel<T> channel) {
+ ChannelAsyncStream(AsyncChannel<T> channel) {
this.channel = channel;
}
diff --git a/src/main/java/groovy/concurrent/AsyncStream.java b/src/main/java/groovy/concurrent/AsyncStream.java
index 5c2176dfe2..ce7017eefa 100644
--- a/src/main/java/groovy/concurrent/AsyncStream.java
+++ b/src/main/java/groovy/concurrent/AsyncStream.java
@@ -35,7 +35,7 @@ package groovy.concurrent;
* to create a generator-style stream</li>
* <li>Adapting JDK {@link java.util.concurrent.Flow.Publisher} instances
* (supported out of the box by the built-in adapter)</li>
- * <li>Viewing a {@link Channel} as a stream via {@link Channel#asStream()} —
+ * <li>Viewing a {@link AsyncChannel} as a stream via {@link AsyncChannel#asStream()} —
* each {@code moveNext()} call maps to a {@code receive()}, and
* {@link ChannelClosedException} is translated to end-of-stream.
* This conversion is registered automatically, so {@code for await (item in channel)}
diff --git a/src/main/java/groovy/concurrent/Awaitable.java b/src/main/java/groovy/concurrent/Awaitable.java
index 37488abd2f..f9c4b96a55 100644
--- a/src/main/java/groovy/concurrent/Awaitable.java
+++ b/src/main/java/groovy/concurrent/Awaitable.java
@@ -383,7 +383,7 @@ public interface Awaitable<T> {
* @return a new unbuffered channel
* @since 6.0.0
*/
- static <T> Channel<T> channel() {
+ static <T> AsyncChannel<T> channel() {
return AsyncSupport.channel();
}
@@ -395,7 +395,7 @@ public interface Awaitable<T> {
* @return a new channel
* @since 6.0.0
*/
- static <T> Channel<T> channel(int capacity) {
+ static <T> AsyncChannel<T> channel(int capacity) {
return AsyncSupport.channel(capacity);
}
diff --git a/src/main/java/groovy/concurrent/AwaitableAdapterRegistry.java b/src/main/java/groovy/concurrent/AwaitableAdapterRegistry.java
index e3921763d9..7db66e9132 100644
--- a/src/main/java/groovy/concurrent/AwaitableAdapterRegistry.java
+++ b/src/main/java/groovy/concurrent/AwaitableAdapterRegistry.java
@@ -181,8 +181,8 @@ public class AwaitableAdapterRegistry {
/**
* Converts the given source to an {@link AsyncStream}.
* If the source is already an {@code AsyncStream}, it is returned as-is.
- * {@link Channel} instances are handled as a built-in special case via
- * {@link Channel#asStream()}, enabling transparent {@code for await}
+ * {@link AsyncChannel} instances are handled as a built-in special case via
+ * {@link AsyncChannel#asStream()}, enabling transparent {@code for await}
* iteration over channels.
* <p>
* Uses a per-class {@link ClassValue} cache to avoid repeated linear
@@ -205,7 +205,7 @@ public class AwaitableAdapterRegistry {
throw new IllegalArgumentException("Cannot convert null to AsyncStream");
}
if (source instanceof AsyncStream) return (AsyncStream<T>) source;
- if (source instanceof Channel) return ((Channel<T>) source).asStream();
+ if (source instanceof AsyncChannel) return ((AsyncChannel<T>) source).asStream();
Class<?> type = source.getClass();
AwaitableAdapter adapter = streamCache.get(type);
if (adapter != null) {
diff --git a/src/main/java/groovy/concurrent/ChannelClosedException.java b/src/main/java/groovy/concurrent/ChannelClosedException.java
index e71fd02138..2c045b2edc 100644
--- a/src/main/java/groovy/concurrent/ChannelClosedException.java
+++ b/src/main/java/groovy/concurrent/ChannelClosedException.java
@@ -19,7 +19,7 @@
package groovy.concurrent;
/**
- * Indicates that a {@link Channel} operation was attempted after the channel
+ * Indicates that a {@link AsyncChannel} operation was attempted after the channel
* had been closed.
*
* @since 6.0.0
diff --git a/src/main/java/org/apache/groovy/runtime/async/AsyncSupport.java b/src/main/java/org/apache/groovy/runtime/async/AsyncSupport.java
index 20f13ba991..3c6d4b3bc8 100644
--- a/src/main/java/org/apache/groovy/runtime/async/AsyncSupport.java
+++ b/src/main/java/org/apache/groovy/runtime/async/AsyncSupport.java
@@ -23,7 +23,7 @@ import groovy.concurrent.AsyncScope;
import groovy.concurrent.AsyncStream;
import groovy.concurrent.AwaitResult;
import groovy.concurrent.Awaitable;
-import groovy.concurrent.Channel;
+import groovy.concurrent.AsyncChannel;
import groovy.lang.Closure;
import java.lang.invoke.MethodHandle;
@@ -939,8 +939,8 @@ public class AsyncSupport {
* @param <T> the payload type
* @return a new unbuffered channel
*/
- public static <T> Channel<T> channel() {
- return new Channel<>();
+ public static <T> AsyncChannel<T> channel() {
+ return new AsyncChannel<>();
}
/**
@@ -950,8 +950,8 @@ public class AsyncSupport {
* @param <T> the payload type
* @return a new channel
*/
- public static <T> Channel<T> channel(int capacity) {
- return new Channel<>(capacity);
+ public static <T> AsyncChannel<T> channel(int capacity) {
+ return new AsyncChannel<>(capacity);
}
// ---- executor configuration -----------------------------------------
diff --git a/src/spec/doc/core-async-await.adoc b/src/spec/doc/core-async-await.adoc
index 1e5a98287f..8c53354338 100644
--- a/src/spec/doc/core-async-await.adoc
+++ b/src/spec/doc/core-async-await.adoc
@@ -40,7 +40,7 @@ Key capabilities include:
* **`yield return`** — produce asynchronous streams (generators)
* **`defer`** — schedule cleanup actions that run when the method completes (LIFO order)
* **`AsyncContext`** — propagate request, trace, and tenant metadata across async boundaries
-* **`Awaitable.go`, `Channel`, and `Awaitable.any`** — task spawning and channel-based communication primitives
+* **`Awaitable.go`, `AsyncChannel`, and `Awaitable.any`** — task spawning and channel-based communication primitives
* **Framework integration** — built-in adapters for `CompletableFuture` and `Future`;
`Flow.Publisher` support via an auto-discovered runtime adapter;
extensible to RxJava, Reactor, and Spring via the adapter registry
@@ -433,7 +433,7 @@ include::../test/AsyncAwaitSpecTest.groovy[tags=async_lambda,indent=0]
[[for_await_section]]
== `for await` — Async Iteration
-The `for await` loop iterates over asynchronous data sources (`AsyncStream`, `Flow.Publisher`, `Channel`, `Iterable`).
+The `for await` loop iterates over asynchronous data sources (`AsyncStream`, `Flow.Publisher`, `AsyncChannel`, `Iterable`).
Each element is resolved asynchronously before the loop body executes. This is analogous to JavaScript's
`for await...of` and C#'s `await foreach`.
@@ -766,7 +766,7 @@ include::../test/AsyncAwaitSpecTest.groovy[tags=from_conversion,indent=0]
`Awaitable.from()` accepts any type supported by a registered adapter: `CompletableFuture`,
`CompletionStage`, `Future`, `Flow.Publisher`, or any third-party type with a custom adapter.
If the source is already an `Awaitable`, it is returned as-is. `AsyncStream.from()` works
-similarly for multi-value sources such as `Iterable`, `Iterator`, `Channel`, or `Flow.Publisher`.
+similarly for multi-value sources such as `Iterable`, `Iterator`, `AsyncChannel`, or `Flow.Publisher`.
=== Built-in Adapters
@@ -776,7 +776,7 @@ asynchronous types from third-party frameworks. The built-in adapter handles:
* `groovy.concurrent.Awaitable` (native Groovy promise — passthrough)
* `java.util.concurrent.CompletableFuture` and `CompletionStage`
* `java.util.concurrent.Future` (blocking, delegated to a configurable executor)
-* `groovy.concurrent.Channel` (automatically converted to `AsyncStream` for `for await`)
+* `groovy.concurrent.AsyncChannel` (automatically converted to `AsyncStream` for `for await`)
Additionally, `java.util.concurrent.Flow.Publisher` support (single-value `await` and
multi-value `for await`) is provided by an internal runtime adapter
@@ -1254,10 +1254,10 @@ JavaScript, C#, Kotlin, and Swift, for developers familiar with those languages.
| **Async iteration**
| `for await (x in src) { }` +
-_(supports `AsyncStream`, `Flow.Publisher`, `Channel`, `Iterable`)_
+_(supports `AsyncStream`, `Flow.Publisher`, `AsyncChannel`, `Iterable`)_
| `for await (x of src) { }`
| `await foreach (x in src) { }`
-| _(manual via `Flow`, `Channel`, or `Flow.collect`)_
+| _(manual via `Flow`, `AsyncChannel`, or `Flow.collect`)_
| `for try await x in seq`
| **Channels**
@@ -1266,8 +1266,8 @@ _(supports `AsyncStream`, `Flow.Publisher`, `Channel`, `Iterable`)_
`for await (x in ch) { }`
| _(none; use streams or message ports)_
| `System.Threading.Channels` +
-`Channel<T>` / `ChannelReader.ReadAllAsync()`
-| `Channel<T>` / `channel.send()` +
+`AsyncChannel<T>` / `ChannelReader.ReadAllAsync()`
+| `AsyncChannel<T>` / `channel.send()` +
`for (x in channel) { }`
| `AsyncStream` / `AsyncChannel` (3rd party)
@@ -1588,7 +1588,7 @@ channels, timers, and arbitrary async tasks — serving a similar role to Go's
=== Iterating Channels with `for await`
-Because `Channel` integrates with the <<for_await_section,`for await`>> syntax,
+Because `AsyncChannel` integrates with the <<for_await_section,`for await`>> syntax,
you can iterate received values in a natural loop — the Groovy equivalent of Go's
`for range ch`:
@@ -1598,7 +1598,7 @@ include::../test/AsyncAwaitSpecTest.groovy[tags=for_await_channel,indent=0]
----
Internally, `for await` obtains a read-only `AsyncStream` view from the channel
-(via `Channel.asStream()`). Each iteration calls `receive()`; when the channel is
+(via `AsyncChannel.asStream()`). Each iteration calls `receive()`; when the channel is
closed and all buffered values are drained, the stream signals completion and the
loop exits.
@@ -1631,7 +1631,7 @@ should _not_ be confused or substituted for each other:
[cols="1,2,2"]
|===
-| Aspect | Channel | `Flow.Publisher`
+| Aspect | AsyncChannel | `Flow.Publisher`
| **Model**
| Bidirectional send/receive (CSP)
diff --git a/src/spec/test/AsyncAwaitSpecTest.groovy b/src/spec/test/AsyncAwaitSpecTest.groovy
index 0e17056efd..db83cb2003 100644
--- a/src/spec/test/AsyncAwaitSpecTest.groovy
+++ b/src/spec/test/AsyncAwaitSpecTest.groovy
@@ -1777,7 +1777,7 @@ import java.util.concurrent.Flow
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
-// --- Channel: Go-style coordination primitive ---
+// --- AsyncChannel: Go-style coordination primitive ---
// Producers and consumers communicate through explicit send/receive.
// Best for task-to-task coordination and fan-in/fan-out pipelines.
def channelItems = []
@@ -1820,7 +1820,7 @@ for await (item in publisher) {
}
assert publisherItems == [100, 200, 300]
-// Both Channel and Flow.Publisher work with 'for await' through
+// Both AsyncChannel and Flow.Publisher work with 'for await' through
// the unified AsyncStream abstraction — same syntax, different use cases.
// end::channel_vs_flow_for_await[]
'''
diff --git a/src/test/groovy/org/codehaus/groovy/transform/AsyncApiTest.groovy b/src/test/groovy/org/codehaus/groovy/transform/AsyncApiTest.groovy
index 89838cb7f9..696594c10b 100644
--- a/src/test/groovy/org/codehaus/groovy/transform/AsyncApiTest.groovy
+++ b/src/test/groovy/org/codehaus/groovy/transform/AsyncApiTest.groovy
@@ -64,7 +64,7 @@ import static groovy.test.GroovyAssert.shouldFail
* Every test in this class exercises the public API of {@code AsyncSupport},
* {@code AsyncStreamGenerator}, {@code GroovyPromise}, {@code Awaitable},
* {@code AwaitResult}, {@code AwaitableAdapterRegistry}, {@code AsyncScope},
- * {@code AsyncContext}, {@code Channel}, and {@code FlowPublisherAdapter}
+ * {@code AsyncContext}, {@code AsyncChannel}, and {@code FlowPublisherAdapter}
* directly — without {@code assertScript} or compiler-driven async
* transformation. This ensures JaCoCo instrumentation captures coverage
* accurately for the runtime classes.
@@ -4187,7 +4187,7 @@ class AsyncApiTest {
}
}
- // --- Channel / FlowPublisher ---
+ // --- AsyncChannel / FlowPublisher ---
@Test
void testChannelGetCapacity() {
@@ -4204,7 +4204,7 @@ class AsyncApiTest {
@Test
void testChannelToString() {
def ch = Awaitable.channel(5)
- assert ch.toString().contains('Channel')
+ assert ch.toString().contains('AsyncChannel')
ch.close()
assert ch.toString().contains('closed')
}
diff --git a/src/test/groovy/org/codehaus/groovy/transform/AsyncContextChannelTest.groovy b/src/test/groovy/org/codehaus/groovy/transform/AsyncContextChannelTest.groovy
index 4a8e5c90fa..83e0fd9389 100644
--- a/src/test/groovy/org/codehaus/groovy/transform/AsyncContextChannelTest.groovy
+++ b/src/test/groovy/org/codehaus/groovy/transform/AsyncContextChannelTest.groovy
@@ -382,9 +382,9 @@ final class AsyncContextChannelTest {
@Test
void testBufferedChannelSendCompletesImmediately() {
assertScript '''
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
- def channel = new Channel<String>(2)
+ def channel = new AsyncChannel<String>(2)
def s1 = channel.send('a')
def s2 = channel.send('b')
@@ -430,10 +430,10 @@ final class AsyncContextChannelTest {
@Test
void testChannelCloseFailsReceiversAfterDrain() {
shouldFail '''
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
import groovy.concurrent.ChannelClosedException
- def channel = new Channel<String>(1)
+ def channel = new AsyncChannel<String>(1)
await channel.send('first')
assert channel.close()
assert await(channel.receive()) == 'first'
@@ -444,25 +444,25 @@ final class AsyncContextChannelTest {
@Test
void testChannelRejectsNullPayload() {
shouldFail '''
- import groovy.concurrent.Channel
- new Channel<String>(1).send(null)
+ import groovy.concurrent.AsyncChannel
+ new AsyncChannel<String>(1).send(null)
'''
}
@Test
void testChannelRejectsNegativeCapacity() {
shouldFail '''
- import groovy.concurrent.Channel
- new Channel<String>(-1)
+ import groovy.concurrent.AsyncChannel
+ new AsyncChannel<String>(-1)
'''
}
@Test
void testChannelCloseIsIdempotent() {
assertScript '''
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
- def channel = new Channel<String>(1)
+ def channel = new AsyncChannel<String>(1)
assert channel.close()
assert !channel.close()
'''
@@ -471,10 +471,10 @@ final class AsyncContextChannelTest {
@Test
void testChannelSendOnClosedChannel() {
shouldFail '''
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
import groovy.concurrent.ChannelClosedException
- def channel = new Channel<String>(1)
+ def channel = new AsyncChannel<String>(1)
channel.close()
await channel.send('late')
'''
@@ -483,10 +483,10 @@ final class AsyncContextChannelTest {
@Test
void testChannelClosePreservesBufferedValues() {
assertScript '''
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
import static groovy.test.GroovyAssert.shouldFail
- def channel = new Channel<Integer>(5)
+ def channel = new AsyncChannel<Integer>(5)
await channel.send(1)
await channel.send(2)
@@ -506,9 +506,9 @@ final class AsyncContextChannelTest {
@Test
void testChannelCloseDrainsBufferToWaitingReceivers() {
assertScript '''
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
- def channel = new Channel<String>(2)
+ def channel = new AsyncChannel<String>(2)
await channel.send('a')
await channel.send('b')
@@ -525,9 +525,9 @@ final class AsyncContextChannelTest {
@Test
void testChannelToString() {
assertScript '''
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
- def channel = new Channel<String>(5)
+ def channel = new AsyncChannel<String>(5)
await channel.send('a')
def str = channel.toString()
assert str.contains('capacity=5')
@@ -603,10 +603,10 @@ final class AsyncContextChannelTest {
void testAnyWithMultipleChannels() {
assertScript '''
import groovy.concurrent.Awaitable
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
- def ch1 = new Channel<String>(1)
- def ch2 = new Channel<String>(1)
+ def ch1 = new AsyncChannel<String>(1)
+ def ch2 = new AsyncChannel<String>(1)
await ch2.send('from-ch2')
@@ -876,9 +876,9 @@ final class AsyncContextChannelTest {
@Test
void testForAwaitOverEmptyClosedChannel() {
assertScript '''
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
- def ch = new Channel<String>(1)
+ def ch = new AsyncChannel<String>(1)
ch.close()
def items = []
@@ -957,9 +957,9 @@ final class AsyncContextChannelTest {
@Test
void testChannelAsStreamExplicit() {
assertScript '''
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
- def ch = new Channel<Integer>(3)
+ def ch = new AsyncChannel<Integer>(3)
await ch.send(10)
await ch.send(20)
await ch.send(30)
@@ -1440,7 +1440,7 @@ final class AsyncContextChannelTest {
void testChannelStreamViewCheckedExceptionWrap() {
assertScript '''
import groovy.concurrent.Awaitable
- import groovy.concurrent.Channel
+ import groovy.concurrent.AsyncChannel
async def checkedExceptionTest() {
def ch = Awaitable.channel(1)
@@ -1489,7 +1489,7 @@ final class AsyncContextChannelTest {
import groovy.concurrent.Awaitable
def ch = Awaitable.channel(5)
- assert ch.toString().contains('Channel')
+ assert ch.toString().contains('AsyncChannel')
assert ch.toString().contains('capacity=5')
ch.close()