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 6d12000  polish wording
6d12000 is described below

commit 6d120002f2a1a3d86cf80ea92e914f01a13510d0
Author: Paul King <[email protected]>
AuthorDate: Wed Apr 8 08:33:27 2026 +1000

    polish wording
---
 site/src/site/blog/groovy-async-await.adoc | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/site/src/site/blog/groovy-async-await.adoc 
b/site/src/site/blog/groovy-async-await.adoc
index 65c7fb9..e011e66 100644
--- a/site/src/site/blog/groovy-async-await.adoc
+++ b/site/src/site/blog/groovy-async-await.adoc
@@ -404,21 +404,21 @@ is a race condition:
 
 [source,groovy]
 ----
-// UNSAFE
-var count = 0
-def tasks = (1..100).collect { async { count++ } }
+// UNSAFE — shared mutation is a race condition
+var total = 0
+def tasks = heroes.collect { h -> async { total += fetchScore(h) } }
 tasks.each { await it }
-// count may not be 100!
+// total may be wrong!
 ----
 
 Return values and collect results instead:
 
 [source,groovy]
 ----
-// SAFE
-def tasks = (1..100).collect { n -> async { n } }
+// SAFE — each task returns its result
+def tasks = heroes.collect { h -> async { fetchScore(h) } }
 def results = await Awaitable.all(*tasks)
-assert results.sum() == 5050
+def total = results.sum()
 ----
 
 When shared mutable state is unavoidable, use the appropriate

Reply via email to