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 74dc40e async/await draft post (fix orTimeout example)
74dc40e is described below
commit 74dc40e54bfb644a368466d6bb72af8fb0067713
Author: Paul King <[email protected]>
AuthorDate: Fri Mar 27 09:46:45 2026 +1000
async/await draft post (fix orTimeout example)
---
site/src/site/blog/groovy-async-await.adoc | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/site/src/site/blog/groovy-async-await.adoc
b/site/src/site/blog/groovy-async-await.adoc
index e03ae49..74ec24f 100644
--- a/site/src/site/blog/groovy-async-await.adoc
+++ b/site/src/site/blog/groovy-async-await.adoc
@@ -342,14 +342,7 @@ cancelled:
----
async raidWithTimeLimit(List<Hero> party, List<Room> rooms) {
try {
- await Awaitable.orTimeoutMillis(30_000) {
- AsyncScope.withScope { scope ->
- var missions = unique(party, rooms).collect { hero, room ->
- scope.async { await hero.scout(room) }
- }
- missions.collect { await it }
- }
- }
+ await Awaitable.orTimeout(raidDungeon(party, rooms), 30, SECONDS)
} catch (TimeoutException e) {
party.each { it.retreat() }
return [] // no loot this time
@@ -361,6 +354,13 @@ When the timeout fires, the scope's child tasks are
cancelled and
a `TimeoutException` is thrown — which you handle with an ordinary
`catch`, just like any other error.
+In simple cases, you can also use `completeOnTimeout`:
+
+[source,groovy]
+----
+var loot = await Awaitable.completeOnTimeout(raidDungeon(heroes, rooms), [],
30, SECONDS)
+----
+
=== Complementing JDK structured concurrency
Java's `StructuredTaskScope`