[
https://issues.apache.org/jira/browse/GROOVY-12721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140066#comment-18140066
]
ASF GitHub Bot commented on GROOVY-12721:
-----------------------------------------
codeconsole opened a new pull request, #3255:
URL: https://github.com/apache/groovy/pull/3255
https://issues.apache.org/jira/browse/GROOVY-12721
`Awaitable.all`, `any`, `first` and `allSettled` take `Object... sources`. A
list of tasks, the usual shape when they come out of `collect`, had to be
spread (`Awaitable.allSettled(*tasks)`); passing the list itself compiled and
failed at run time with "No Awaitable adapter found for type:
java.util.ArrayList". That is the form JavaScript's `Promise.all(iterable)`
taught, and the one a model with the Groovy docs in front of it still wrote.
A collection is never awaitable, so a single `Collection` argument has no
other meaning. `AwaitCombinators` now takes such an argument's elements as the
sources, for the four async combinators and so for the blocking forms that
delegate to them; the empty and null checks of `any` and `first` apply to those
elements. The spread form keeps working.
```groovy
def tasks = ['a', 'b', 'c'].collect { m -> async { fetch(m) } }
def results = await Awaitable.allSettled(tasks)
```
Docs: a tip in the combinator summary of `core-async-await.adoc`, and the
`@param sources` lines of the four methods. Tests:
`AsyncAwaitTest.testCombinatorsTakeOneListOfSources` (list and set, empty list,
the four combinators, the empty and null rejections). Also run locally:
`groovy.AsyncAwaitTest` and `org.apache.groovy.runtime.async.*`, 370 tests,
passing.
> Awaitable.all, any, first and allSettled should accept a single list of
> sources
> -------------------------------------------------------------------------------
>
> Key: GROOVY-12721
> URL: https://issues.apache.org/jira/browse/GROOVY-12721
> Project: Groovy
> Issue Type: Improvement
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {{Awaitable.all}}, {{any}}, {{first}} and {{allSettled}} take {{Object...
> sources}}. A caller holding a list of tasks, the usual shape when the tasks
> come out of {{collect}}, has to spread it: {{Awaitable.allSettled(*tasks)}}.
> Passing the list itself compiles and fails at run time with a message about
> the list's class:
> {code:groovy}
> def tasks = ['a', 'b', 'c'].collect { m -> async { fetch(m) } }
> def results = await Awaitable.allSettled(tasks)
> {code}
> {noformat}
> IllegalArgumentException: No Awaitable adapter found for type:
> java.util.ArrayList. Register an AwaitableAdapter via ServiceLoader or
> AwaitableAdapterRegistry.register().
> {noformat}
> JavaScript's {{Promise.all}}, {{allSettled}}, {{any}} and {{race}} take an
> iterable, so this is the form people, and the models trained on them, write
> first. A single argument that is a {{Collection}} has no other meaning today,
> since a collection is never awaitable, so the combinators can take it as the
> list of sources.
> Proposal: in {{AwaitCombinators}}, when {{sources}} has one element and it is
> a {{Collection}}, use its elements; the empty and null checks of {{any}} and
> {{first}} then apply to those elements. {{Awaitable.all(*tasks)}} keeps
> working. A sentence in the combinator summary of core-async-await.adoc and in
> the {{@param sources}} Javadoc.
> Found while scoring Groovy 6.0.0 code written by a language model: with the
> Groovy documentation available to it through a tool, GPT-6 still wrote the
> list form.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)