File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
main/groovy/org/grails/async/factory Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit
3030class 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) {
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments