This is an automated email from the ASF dual-hosted git repository.
git-site-role pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-dev-site.git
The following commit(s) were added to refs/heads/asf-site by this push:
new f919cff 2026/04/01 03:55:09: Generated dev website from
groovy-website@607aee5
f919cff is described below
commit f919cff1e69b5f0c19e7ab2dae2de8c929107bc5
Author: jenkins <[email protected]>
AuthorDate: Wed Apr 1 03:55:09 2026 +0000
2026/04/01 03:55:09: Generated dev website from groovy-website@607aee5
---
blog/groovy-async-await.html | 41 ++++++++++++++++++++++++++++++++++++-----
search/search-index.json | 2 +-
2 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/blog/groovy-async-await.html b/blog/groovy-async-await.html
index ec01568..716944b 100644
--- a/blog/groovy-async-await.html
+++ b/blog/groovy-async-await.html
@@ -260,7 +260,7 @@ common pattern. Here’s how it looks with
<code>Awaitable.all</code>:</p>
var inventory = async { fetchInventory(heroId) }
var villain = async { fetchVillain(visibleVillainId) }
- var (s, inv, v) = await Awaitable.all(stats(), inventory(), villain())
+ var (s, inv, v) = await stats(), inventory(), villain()
return new BattleScreen(s, inv, v)
}</code></pre>
</div>
@@ -268,7 +268,12 @@ common pattern. Here’s how it looks with
<code>Awaitable.all</code>:</p>
<div class="paragraph">
<p>Here, <code>async { … }</code> creates an async closure — a reusable
block that doesn’t run until you call it.
-Invoking <code>stats()</code>, <code>inventory()</code>, and
<code>villain()</code> each launches its respective block concurrently and
returns an <code>Awaitable</code>. The <code>all</code> combinator produces
another <code>Awaitable</code> that completes when every task has finished. If
any task fails, the remaining tasks still run to completion, and the first
exception is thrown unwrapped. (For fail-fast semantics — cancelling siblings
as soon as one fails — see <code>AsyncScope</cod [...]
+Invoking <code>stats()</code>, <code>inventory()</code>, and
<code>villain()</code> each launches its respective block concurrently and
returns an <code>Awaitable</code>.</p>
+</div>
+<div class="paragraph">
+<p>The <code>await stats(), inventory(), villain()</code> statement is a
shorthand for
+<code>await Awaitable.all(stats(), inventory(), villain())</code>.
+The <code>all</code> combinator produces another <code>Awaitable</code> that
completes when every task has finished. If any task fails, the remaining tasks
still run to completion, and the first exception is thrown unwrapped. (For
fail-fast semantics — cancelling siblings as soon as one fails — see
<code>AsyncScope</code> in Example 6.)</p>
</div>
<div class="sect2">
<h3 id="_how_this_compares_to_javas_structuredtaskscope">How this compares to
Java’s <code>StructuredTaskScope</code></h3>
@@ -301,8 +306,9 @@ in <a href="#_example_6_the_raid_party">Example 6</a>.</p>
</div>
<div class="paragraph">
<p>Note that this isn’t an exact equivalent of our Groovy example.
-The async factory-like closures are reusable. To more closely mirror
-the Java version we could use <code>Awaitable.go</code>:</p>
+The async factory-like closures are reusable. If you don’t need that
+flexibility, you can also use <code>Awaitable.go</code> to launch a one-off
task.
+This more closely mirrors the Java version:</p>
</div>
<div class="listingblock">
<div class="content">
@@ -311,12 +317,37 @@ the Java version we could use
<code>Awaitable.go</code>:</p>
var inventory = Awaitable.go { fetchInventory(heroId) }
var villain = Awaitable.go { fetchVillain(visibleVillainId) }
- await Awaitable.all(stats, inventory, villain)
+ await stats, inventory, villain
return new BattleScreen(stats.get(), inventory.get(), villain.get())
}</code></pre>
</div>
</div>
</div>
+<div class="sect2">
+<h3 id="_the_flip_side_awaitable_any_first_one_wins">The flip side:
<code>Awaitable.any</code> — first one wins</h3>
+<div class="paragraph">
+<p>Where <code>all</code> waits for <em>every</em> task, <code>any</code>
returns as soon as the
+<em>first</em> one completes — a race. Imagine a capture-the-flag battle
+where the hero and villain both dash for the flag:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code data-lang="groovy">async
captureTheFlag(hero, villain, flag) {
+ var heroGrab = async { hero.grab(flag) }
+ var villainGrab = async { villain.grab(flag) }
+
+ var winner = await Awaitable.any(heroGrab(), villainGrab())
+ println "$winner.name captured the flag!"
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>The loser’s task still runs to completion in the background
+(use <code>AsyncScope</code> if you want the loser cancelled immediately).
+This is the same "race" pattern as JavaScript’s <code>Promise.race</code>
+or Go’s <code>select</code>.</p>
+</div>
+</div>
</div>
</div>
<div class="sect1">
diff --git a/search/search-index.json b/search/search-index.json
index 7c7ecaf..a3c547b 100644
--- a/search/search-index.json
+++ b/search/search-index.json
@@ -254,7 +254,7 @@
{
"id": "blog/groovy-async-await.html",
"title": "The Apache Groovy programming language - Blogs - Async/await
for Groovy™",
- "content": "The Apache Groovy programming language - Blogs -
Async/await for Groovy™ Socialize Discuss on the mailing list Groovy on X
Groovy on Bluesky Groovy on Mastodon Groovy on LinkedIn Events and conferences
Source code on GitHub Report issues in Jira Stack Overflow questions Slack
Community You are using an outdated browser. Please upgrade your browser to
improve your experience. Apache Groovy™ Learn Documentation Download
Support Contribute Ecosystem Blog post [...]
+ "content": "The Apache Groovy programming language - Blogs -
Async/await for Groovy™ Socialize Discuss on the mailing list Groovy on X
Groovy on Bluesky Groovy on Mastodon Groovy on LinkedIn Events and conferences
Source code on GitHub Report issues in Jira Stack Overflow questions Slack
Community You are using an outdated browser. Please upgrade your browser to
improve your experience. Apache Groovy™ Learn Documentation Download
Support Contribute Ecosystem Blog post [...]
"url": "blog/groovy-async-await.html",
"site": "dev"
},