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

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


The following commit(s) were added to refs/heads/asf-site by this push:
     new 607aee5  minor changes around all and any
607aee5 is described below

commit 607aee59bff766a77c51464db06772d848c53e17
Author: Paul King <[email protected]>
AuthorDate: Wed Apr 1 13:26:29 2026 +1000

    minor changes around all and any
---
 site/src/site/blog/groovy-async-await.adoc | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/site/src/site/blog/groovy-async-await.adoc 
b/site/src/site/blog/groovy-async-await.adoc
index 0a372dc..9f6349a 100644
--- a/site/src/site/blog/groovy-async-await.adoc
+++ b/site/src/site/blog/groovy-async-await.adoc
@@ -211,6 +211,28 @@ async prepareBattle(heroId, visibleVillainId) {
 }
 ----
 
+=== The flip side: `Awaitable.any` — first one wins
+
+Where `all` waits for _every_ task, `any` returns as soon as the
+_first_ one completes — a race. Imagine a capture-the-flag battle
+where the hero and villain both dash for the flag:
+
+[source,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!"
+}
+----
+
+The loser's task still runs to completion in the background
+(use `AsyncScope` if you want the loser cancelled immediately).
+This is the same "race" pattern as JavaScript's `Promise.race`
+or Go's `select`.
+
 == Example 3: dungeon waves — async streams with `yield return` and `for await`
 
 A dungeon sends waves of enemies at the hero. Each wave is fetched

Reply via email to