Skip to content

Commit 05c86c4

Browse files
committed
Merge branch '3.1.x' into 3.2.x
2 parents 95d2f88 + 4d18ef1 commit 05c86c4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

grails-async/src/main/groovy/org/grails/async/factory/SynchronousPromise.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit
3030
class SynchronousPromise<T> implements Promise<T> {
3131
Closure<T> callable
3232
def value
33+
boolean executed = false
3334

3435
SynchronousPromise(Closure<T> callable) {
3536
this.callable = callable
@@ -51,7 +52,8 @@ class SynchronousPromise<T> implements Promise<T> {
5152
}
5253

5354
T get() throws Throwable {
54-
if (value == null) {
55+
if (!executed) {
56+
executed = true
5557
try {
5658
value = callable.call()
5759
} catch (e) {

grails-async/src/test/groovy/grails/async/SynchronousPromiseFactorySpec.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,18 @@ class SynchronousPromiseFactorySpec extends Specification {
156156
then:'the closure is executed'
157157
1 * callable.call()
158158
}
159+
160+
@Issue("GRAILS-10152")
161+
void "Test promise closure is not executed multiple times if it returns null"() {
162+
given:
163+
Closure callable = Mock(Closure) {
164+
call() >> null
165+
}
166+
167+
when:"A promise is created"
168+
Promises.waitAll([Promises.createPromise(callable), Promises.createPromise(callable)])
169+
170+
then:'the closure is executed twice'
171+
2 * callable.call()
172+
}
159173
}

0 commit comments

Comments
 (0)