You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/04/19 02:34:54 UTC

(groovy) branch master updated: minor refactor: toBlockingIterable => toIterable method rename

This is an automated email from the ASF dual-hosted git repository.

paulk-asert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new b5dffe79f8 minor refactor: toBlockingIterable => toIterable method rename
b5dffe79f8 is described below

commit b5dffe79f8104591f716edacbc8568410bad7913
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Apr 19 12:34:44 2026 +1000

    minor refactor: toBlockingIterable => toIterable method rename
---
 .../java/groovy/concurrent/AwaitableAdapter.java   | 10 ++++-----
 .../concurrent/AwaitableAdapterRegistry.java       |  6 +++---
 .../apache/groovy/parser/antlr4/AstBuilder.java    |  8 ++++----
 .../apache/groovy/runtime/async/AsyncSupport.java  | 15 +++++++-------
 .../groovy/runtime/async/FlowPublisherAdapter.java |  6 +++---
 .../groovy/transform/AsyncTransformHelper.java     |  8 ++++----
 src/test/groovy/groovy/AsyncAwaitTest.groovy       | 24 +++++++++++-----------
 .../concurrent/FlowPublisherAdapterTest.groovy     |  8 ++++----
 .../groovy/reactor/ReactorAwaitableAdapter.java    |  2 +-
 .../reactor/ReactorAwaitableAdapterTest.groovy     | 12 +++++------
 .../groovy/rxjava/RxJavaAwaitableAdapter.java      |  2 +-
 .../rxjava/RxJavaAwaitableAdapterTest.groovy       | 12 +++++------
 12 files changed, 57 insertions(+), 56 deletions(-)

diff --git a/src/main/java/groovy/concurrent/AwaitableAdapter.java b/src/main/java/groovy/concurrent/AwaitableAdapter.java
index c5e5aa292f..bb24114ad8 100644
--- a/src/main/java/groovy/concurrent/AwaitableAdapter.java
+++ b/src/main/java/groovy/concurrent/AwaitableAdapter.java
@@ -20,7 +20,7 @@ package groovy.concurrent;
 
 /**
  * Service Provider Interface (SPI) for adapting third-party asynchronous types
- * to Groovy's {@link Awaitable} abstraction and to blocking iterables for
+ * to Groovy's {@link Awaitable} abstraction and to iterables for
  * {@code for await} loops.
  * <p>
  * Implementations are discovered automatically via {@link java.util.ServiceLoader}.
@@ -47,7 +47,7 @@ public interface AwaitableAdapter {
 
     /**
      * Returns {@code true} if this adapter can convert instances of the given
-     * type to a blocking {@link Iterable} for {@code for await} loops.
+     * type to an {@link Iterable} for {@code for await} loops.
      * Defaults to {@code false}; override for multi-value async types
      * (e.g., Reactor {@code Flux}, RxJava {@code Observable}).
      */
@@ -56,12 +56,12 @@ public interface AwaitableAdapter {
     }
 
     /**
-     * Converts the given source object to a blocking {@link Iterable}.
+     * Converts the given source object to an {@link Iterable}.
      * Called only when {@link #supportsIterable} returned {@code true}.
-     * The returned iterable should block on {@code next()} until the
+     * The returned iterable typically blocks on {@code next()} until the
      * next element is available — with virtual threads this is efficient.
      */
-    default <T> Iterable<T> toBlockingIterable(Object source) {
+    default <T> Iterable<T> toIterable(Object source) {
         throw new UnsupportedOperationException("Iterable conversion not supported by " + getClass().getName());
     }
 }
diff --git a/src/main/java/groovy/concurrent/AwaitableAdapterRegistry.java b/src/main/java/groovy/concurrent/AwaitableAdapterRegistry.java
index 6f2ac9ca0f..d588cef38a 100644
--- a/src/main/java/groovy/concurrent/AwaitableAdapterRegistry.java
+++ b/src/main/java/groovy/concurrent/AwaitableAdapterRegistry.java
@@ -113,17 +113,17 @@ public final class AwaitableAdapterRegistry {
     }
 
     /**
-     * Converts the given source to a blocking {@link Iterable} for {@code for await}.
+     * Converts the given source to an {@link Iterable} for {@code for await}.
      */
     @SuppressWarnings("unchecked")
-    public static <T> Iterable<T> toBlockingIterable(Object source) {
+    public static <T> Iterable<T> toIterable(Object source) {
         if (source == null) {
             throw new IllegalArgumentException("Cannot convert null to Iterable");
         }
         Class<?> type = source.getClass();
         for (AwaitableAdapter adapter : adapters) {
             if (adapter.supportsIterable(type)) {
-                return adapter.toBlockingIterable(source);
+                return adapter.toIterable(source);
             }
         }
         throw new IllegalArgumentException(
diff --git a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 4f5aad5a3e..3e5cedcfce 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -476,14 +476,14 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
         visitAnnotationsOpt(ctx.annotationsOpt()).forEach(forStatement::addStatementAnnotation);
 
         if (isForAwait) {
-            // Transform collection expression: wrap in AsyncSupport.toBlockingIterable()
+            // Transform collection expression: wrap in AsyncSupport.toIterable()
             // and wrap the loop in try/finally to ensure cleanup on break/exception
             Expression original = forStatement.getCollectionExpression();
             String tempVar = "__forAwaitSource" + ctx.hashCode();
-            Expression toBlockingCall = AsyncTransformHelper.buildToBlockingIterableCall(original);
+            Expression toIterableCall = AsyncTransformHelper.buildToIterableCall(original);
 
-            // var $temp = AsyncSupport.toBlockingIterable(original)
-            Statement declStmt = stmt(declX(varX(tempVar), toBlockingCall));
+            // var $temp = AsyncSupport.toIterable(original)
+            Statement declStmt = stmt(declX(varX(tempVar), toIterableCall));
             forStatement.setCollectionExpression(varX(tempVar));
 
             // try { for (...) { body } } finally { AsyncSupport.closeIterable($temp) }
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 27fe41b376..3fb625ec0a 100644
--- a/src/main/java/org/apache/groovy/runtime/async/AsyncSupport.java
+++ b/src/main/java/org/apache/groovy/runtime/async/AsyncSupport.java
@@ -360,19 +360,20 @@ public class AsyncSupport {
         return () -> bridge;
     }
 
-    // ---- for-await (blocking iterable conversion) -----------------------
+    // ---- for-await (iterable conversion) --------------------------------
 
     /**
-     * Converts an arbitrary source to a blocking {@link Iterable} for use
-     * in {@code for await} loops. Handles arrays, collections, iterables,
-     * iterators, and adapter-supported types.
+     * Converts an arbitrary source to an {@link Iterable} for use in
+     * {@code for await} loops. Handles arrays, collections, iterables,
+     * iterators, and adapter-supported types. The returned iterable may
+     * block on {@code next()} for async sources.
      *
      * @param source the source to convert
      * @param <T>    the element type
-     * @return a blocking iterable
+     * @return an iterable
      */
     @SuppressWarnings("unchecked")
-    public static <T> Iterable<T> toBlockingIterable(Object source) {
+    public static <T> Iterable<T> toIterable(Object source) {
         if (source == null) return Collections.emptyList();
         if (source instanceof Iterable) return (Iterable<T>) source;
         if (source instanceof Iterator) {
@@ -381,7 +382,7 @@ public class AsyncSupport {
         }
         if (source instanceof Object[]) return (Iterable<T>) Arrays.asList((Object[]) source);
         // Try adapter registry
-        return groovy.concurrent.AwaitableAdapterRegistry.toBlockingIterable(source);
+        return groovy.concurrent.AwaitableAdapterRegistry.toIterable(source);
     }
 
     /**
diff --git a/src/main/java/org/apache/groovy/runtime/async/FlowPublisherAdapter.java b/src/main/java/org/apache/groovy/runtime/async/FlowPublisherAdapter.java
index 4f62f098c9..d490a2850d 100644
--- a/src/main/java/org/apache/groovy/runtime/async/FlowPublisherAdapter.java
+++ b/src/main/java/org/apache/groovy/runtime/async/FlowPublisherAdapter.java
@@ -85,11 +85,11 @@ public final class FlowPublisherAdapter implements AwaitableAdapter {
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> Iterable<T> toBlockingIterable(Object source) {
+    public <T> Iterable<T> toIterable(Object source) {
         if (!(source instanceof Flow.Publisher<?>)) {
             throw new IllegalArgumentException("Cannot convert to Iterable: " + source.getClass());
         }
-        return (Iterable<T>) publisherToBlockingIterable((Flow.Publisher<Object>) source, DEFAULT_BATCH_SIZE);
+        return (Iterable<T>) publisherToIterable((Flow.Publisher<Object>) source, DEFAULT_BATCH_SIZE);
     }
 
     // ---- single-value: first onNext wins ---------------------------------
@@ -139,7 +139,7 @@ public final class FlowPublisherAdapter implements AwaitableAdapter {
 
     // ---- multi-value: blocking iterable with bounded backpressure --------
 
-    private static <T> Iterable<T> publisherToBlockingIterable(Flow.Publisher<T> publisher, int batchSize) {
+    private static <T> Iterable<T> publisherToIterable(Flow.Publisher<T> publisher, int batchSize) {
         return new PublisherBlockingIterable<>(publisher, batchSize);
     }
 
diff --git a/src/main/java/org/codehaus/groovy/transform/AsyncTransformHelper.java b/src/main/java/org/codehaus/groovy/transform/AsyncTransformHelper.java
index 62c7dcd613..60bf4bd5a1 100644
--- a/src/main/java/org/codehaus/groovy/transform/AsyncTransformHelper.java
+++ b/src/main/java/org/codehaus/groovy/transform/AsyncTransformHelper.java
@@ -58,7 +58,7 @@ public final class AsyncTransformHelper {
     private static final String YIELD_RETURN_METHOD = "yieldReturn";
     private static final String ASYNC_METHOD = "async";
     private static final String ASYNC_GENERATOR_METHOD = "asyncGenerator";
-    private static final String TO_BLOCKING_ITERABLE_METHOD = "toBlockingIterable";
+    private static final String TO_ITERABLE_METHOD = "toIterable";
     private static final String CLOSE_ITERABLE_METHOD = "closeIterable";
     private static final String CREATE_DEFER_SCOPE_METHOD = "createDeferScope";
     private static final String DEFER_METHOD = "defer";
@@ -117,10 +117,10 @@ public final class AsyncTransformHelper {
     }
 
     /**
-     * Builds {@code AsyncSupport.toBlockingIterable(source)}.
+     * Builds {@code AsyncSupport.toIterable(source)}.
      */
-    public static Expression buildToBlockingIterableCall(Expression source) {
-        return callX(ASYNC_SUPPORT_TYPE, TO_BLOCKING_ITERABLE_METHOD, ensureArgs(source));
+    public static Expression buildToIterableCall(Expression source) {
+        return callX(ASYNC_SUPPORT_TYPE, TO_ITERABLE_METHOD, ensureArgs(source));
     }
 
     /**
diff --git a/src/test/groovy/groovy/AsyncAwaitTest.groovy b/src/test/groovy/groovy/AsyncAwaitTest.groovy
index eccb188d42..55a5ed5a05 100644
--- a/src/test/groovy/groovy/AsyncAwaitTest.groovy
+++ b/src/test/groovy/groovy/AsyncAwaitTest.groovy
@@ -2427,33 +2427,33 @@ final class AsyncAwaitTest {
     }
 
     @Test
-    void testToBlockingIterableNull() {
+    void testToIterableNull() {
         assertScript '''
             import org.apache.groovy.runtime.async.AsyncSupport
 
-            def result = AsyncSupport.toBlockingIterable(null)
+            def result = AsyncSupport.toIterable(null)
             assert result.collect() == []
         '''
     }
 
     @Test
-    void testToBlockingIterableIterator() {
+    void testToIterableIterator() {
         assertScript '''
             import org.apache.groovy.runtime.async.AsyncSupport
 
             def iter = [1, 2, 3].iterator()
-            def result = AsyncSupport.toBlockingIterable(iter)
+            def result = AsyncSupport.toIterable(iter)
             assert result.collect() == [1, 2, 3]
         '''
     }
 
     @Test
-    void testToBlockingIterableArray() {
+    void testToIterableArray() {
         assertScript '''
             import org.apache.groovy.runtime.async.AsyncSupport
 
             def arr = [10, 20, 30] as Object[]
-            def result = AsyncSupport.toBlockingIterable(arr)
+            def result = AsyncSupport.toIterable(arr)
             assert result.collect() == [10, 20, 30]
         '''
     }
@@ -3368,7 +3368,7 @@ final class AsyncAwaitTest {
     }
 
     @Test
-    void testAdapterRegistryToBlockingIterableWithAdapter() {
+    void testAdapterRegistryToIterableWithAdapter() {
         assertScript '''
             import groovy.concurrent.AwaitableAdapterRegistry
             import groovy.concurrent.AwaitableAdapter
@@ -3378,11 +3378,11 @@ final class AsyncAwaitTest {
                 boolean supportsAwaitable(Class type) { false }
                 Awaitable toAwaitable(Object source) { null }
                 boolean supportsIterable(Class type) { List.isAssignableFrom(type) }
-                Iterable toBlockingIterable(Object source) { (Iterable) source }
+                Iterable toIterable(Object source) { (Iterable) source }
             }
             AwaitableAdapterRegistry.register(adapter)
             try {
-                def iterable = AwaitableAdapterRegistry.toBlockingIterable([1, 2, 3])
+                def iterable = AwaitableAdapterRegistry.toIterable([1, 2, 3])
                 def items = []
                 for (item in iterable) {
                     items << item
@@ -3719,7 +3719,7 @@ final class AsyncAwaitTest {
     }
 
     @Test
-    void testAdapterRegistryToBlockingIterableWithRegisteredAdapter() {
+    void testAdapterRegistryToIterableWithRegisteredAdapter() {
         assertScript """
             import groovy.concurrent.AwaitableAdapterRegistry
             import groovy.concurrent.AwaitableAdapter
@@ -3735,12 +3735,12 @@ final class AsyncAwaitTest {
                 boolean supportsAwaitable(Class type) { false }
                 Awaitable toAwaitable(Object source) { null }
                 boolean supportsIterable(Class type) { type.name.contains('StringIterable') }
-                Iterable toBlockingIterable(Object source) { ((StringIterable)source) }
+                Iterable toIterable(Object source) { ((StringIterable)source) }
             }
             AwaitableAdapterRegistry.register(adapter)
             try {
                 def items = []
-                def iterable = AwaitableAdapterRegistry.toBlockingIterable(new StringIterable('abc'))
+                def iterable = AwaitableAdapterRegistry.toIterable(new StringIterable('abc'))
                 for (ch in iterable) items << ch
                 assert items.size() == 3
             } finally {
diff --git a/src/test/groovy/groovy/concurrent/FlowPublisherAdapterTest.groovy b/src/test/groovy/groovy/concurrent/FlowPublisherAdapterTest.groovy
index 476294747b..ee3de0ac48 100644
--- a/src/test/groovy/groovy/concurrent/FlowPublisherAdapterTest.groovy
+++ b/src/test/groovy/groovy/concurrent/FlowPublisherAdapterTest.groovy
@@ -197,7 +197,7 @@ final class FlowPublisherAdapterTest {
             })
         } as Flow.Publisher<Integer>
 
-        def iterable = AwaitableAdapterRegistry.toBlockingIterable(publisher)
+        def iterable = AwaitableAdapterRegistry.toIterable(publisher)
         assert iterable instanceof AutoCloseable
         def iter = iterable.iterator()
         assert requested.await(5, TimeUnit.SECONDS), 'subscriber never asked to request'
@@ -228,7 +228,7 @@ final class FlowPublisherAdapterTest {
             subscriber.set(sub) // defer onSubscribe
         } as Flow.Publisher<Integer>
 
-        def iterable = AwaitableAdapterRegistry.toBlockingIterable(publisher)
+        def iterable = AwaitableAdapterRegistry.toIterable(publisher)
         iterable.iterator()
         assert subscriber.get() != null
 
@@ -257,7 +257,7 @@ final class FlowPublisherAdapterTest {
             })
         } as Flow.Publisher<Integer>
 
-        def iterable = AwaitableAdapterRegistry.toBlockingIterable(publisher)
+        def iterable = AwaitableAdapterRegistry.toIterable(publisher)
         iterable.iterator()
 
         shouldFail(IllegalStateException) {
@@ -275,7 +275,7 @@ final class FlowPublisherAdapterTest {
         try {
             def awaitable = Awaitable.from(publisher)
             assert awaitable != null
-            def iter = AwaitableAdapterRegistry.toBlockingIterable(publisher)
+            def iter = AwaitableAdapterRegistry.toIterable(publisher)
             assert iter != null
         } finally {
             publisher.close()
diff --git a/subprojects/groovy-reactor/src/main/java/org/apache/groovy/reactor/ReactorAwaitableAdapter.java b/subprojects/groovy-reactor/src/main/java/org/apache/groovy/reactor/ReactorAwaitableAdapter.java
index 7fad09419f..dbd4b6194c 100644
--- a/subprojects/groovy-reactor/src/main/java/org/apache/groovy/reactor/ReactorAwaitableAdapter.java
+++ b/subprojects/groovy-reactor/src/main/java/org/apache/groovy/reactor/ReactorAwaitableAdapter.java
@@ -59,7 +59,7 @@ public class ReactorAwaitableAdapter implements AwaitableAdapter {
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> Iterable<T> toBlockingIterable(Object source) {
+    public <T> Iterable<T> toIterable(Object source) {
         if (source instanceof Flux<?> flux) {
             return (Iterable<T>) flux.toIterable();
         }
diff --git a/subprojects/groovy-reactor/src/test/groovy/org/apache/groovy/reactor/ReactorAwaitableAdapterTest.groovy b/subprojects/groovy-reactor/src/test/groovy/org/apache/groovy/reactor/ReactorAwaitableAdapterTest.groovy
index acb3594a03..a9ca2a8043 100644
--- a/subprojects/groovy-reactor/src/test/groovy/org/apache/groovy/reactor/ReactorAwaitableAdapterTest.groovy
+++ b/subprojects/groovy-reactor/src/test/groovy/org/apache/groovy/reactor/ReactorAwaitableAdapterTest.groovy
@@ -417,16 +417,16 @@ final class ReactorAwaitableAdapterTest {
     }
 
     @Test
-    void testAdapterToBlockingIterableFlux() {
+    void testAdapterToIterableFlux() {
         def adapter = new ReactorAwaitableAdapter()
-        def iter = adapter.toBlockingIterable(Flux.just(1, 2, 3))
+        def iter = adapter.toIterable(Flux.just(1, 2, 3))
         assert iter.collect() == [1, 2, 3]
     }
 
     @Test
-    void testAdapterToBlockingIterableEmptyFlux() {
+    void testAdapterToIterableEmptyFlux() {
         def adapter = new ReactorAwaitableAdapter()
-        def iter = adapter.toBlockingIterable(Flux.empty())
+        def iter = adapter.toIterable(Flux.empty())
         assert iter.collect() == []
     }
 
@@ -442,10 +442,10 @@ final class ReactorAwaitableAdapterTest {
     }
 
     @Test
-    void testAdapterToBlockingIterableUnsupportedType() {
+    void testAdapterToIterableUnsupportedType() {
         def adapter = new ReactorAwaitableAdapter()
         try {
-            adapter.toBlockingIterable('not-reactor')
+            adapter.toIterable('not-reactor')
             assert false : 'should have thrown'
         } catch (IllegalArgumentException e) {
             assert e.message.contains('Cannot convert')
diff --git a/subprojects/groovy-rxjava/src/main/java/org/apache/groovy/rxjava/RxJavaAwaitableAdapter.java b/subprojects/groovy-rxjava/src/main/java/org/apache/groovy/rxjava/RxJavaAwaitableAdapter.java
index 948cff4d43..0cf208caaf 100644
--- a/subprojects/groovy-rxjava/src/main/java/org/apache/groovy/rxjava/RxJavaAwaitableAdapter.java
+++ b/subprojects/groovy-rxjava/src/main/java/org/apache/groovy/rxjava/RxJavaAwaitableAdapter.java
@@ -79,7 +79,7 @@ public class RxJavaAwaitableAdapter implements AwaitableAdapter {
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> Iterable<T> toBlockingIterable(Object source) {
+    public <T> Iterable<T> toIterable(Object source) {
         if (source instanceof Observable<?> observable) {
             return (Iterable<T>) observable.blockingIterable();
         }
diff --git a/subprojects/groovy-rxjava/src/test/groovy/org/apache/groovy/rxjava/RxJavaAwaitableAdapterTest.groovy b/subprojects/groovy-rxjava/src/test/groovy/org/apache/groovy/rxjava/RxJavaAwaitableAdapterTest.groovy
index 74fe428606..671140e545 100644
--- a/subprojects/groovy-rxjava/src/test/groovy/org/apache/groovy/rxjava/RxJavaAwaitableAdapterTest.groovy
+++ b/subprojects/groovy-rxjava/src/test/groovy/org/apache/groovy/rxjava/RxJavaAwaitableAdapterTest.groovy
@@ -552,24 +552,24 @@ final class RxJavaAwaitableAdapterTest {
     }
 
     @Test
-    void testAdapterToBlockingIterableObservable() {
+    void testAdapterToIterableObservable() {
         def adapter = new RxJavaAwaitableAdapter()
-        def iter = adapter.toBlockingIterable(Observable.just(1, 2, 3))
+        def iter = adapter.toIterable(Observable.just(1, 2, 3))
         assert iter.collect() == [1, 2, 3]
     }
 
     @Test
-    void testAdapterToBlockingIterableFlowable() {
+    void testAdapterToIterableFlowable() {
         def adapter = new RxJavaAwaitableAdapter()
-        def iter = adapter.toBlockingIterable(Flowable.just('a', 'b'))
+        def iter = adapter.toIterable(Flowable.just('a', 'b'))
         assert iter.collect() == ['a', 'b']
     }
 
     @Test
-    void testAdapterToBlockingIterableUnsupportedType() {
+    void testAdapterToIterableUnsupportedType() {
         def adapter = new RxJavaAwaitableAdapter()
         try {
-            adapter.toBlockingIterable('not-rx')
+            adapter.toIterable('not-rx')
             assert false : 'should have thrown'
         } catch (IllegalArgumentException e) {
             assert e.message.contains('Cannot convert')