codeconsole opened a new pull request, #3200:
URL: https://github.com/apache/groovy/pull/3200
The closures returned by `AsyncClosureUtils.wrapAsync` and
`wrapAsyncGenerator` copied only the owner and this object of the closure they
wrap. A delegate or resolve strategy set on them was never seen by the wrapped
closure, which resolves the names in the body, so `with { }`, builders and
other DSL use resolved names against the owner:
```groovy
class Ctx { String greet() { 'hi' } }
Closure wrapped = AsyncClosureUtils.wrapAsync { -> greet() }
wrapped.delegate = new Ctx()
wrapped.resolveStrategy = Closure.DELEGATE_FIRST
await(wrapped()) // MissingMethodException: greet for class: Script1
```
They also reported the parameters of their own `doCall(Object...)`, so `[a:
1].collect(AsyncClosureUtils.wrapAsync { k, v -> ... })` passed the map entry
as one argument and failed. Seen in 6.0.0 too. (The `async { }` keyword does
not use these wrappers.)
The wrappers are now nested classes that read and set the delegate and
resolve strategy on the wrapped closure, as `ComposedClosure` does. `clone`,
`dehydrate` and `rehydrate` copy the wrapped closure too, so `with` and
rehydration act on a copy rather than the original. They report the wrapped
closure's parameters; the generator wrapper drops the leading
`GeneratorBridge`, which it supplies itself. Because the getters now forward
through the wrapped closure, it is declared in `additionalReferences()`, and a
deserialized wrapper is checked for reference cycles as Memoize and
TrampolineClosure are. Two commits: delegation, then parameters.
## Tests
These tests in `AsyncAwaitTest` fail without the change:
`testWrapAsyncSetDelegateAndResolveStrategy`,
`testWrapAsyncReportsDelegateAndThisObject`, `testWrapAsyncWith`,
`testWrapAsyncDehydrateAndRehydrate`, `testWrapAsyncReportsParameters`,
`testWrapAsyncGeneratorSetDelegateAndResolveStrategy`,
`testWrapAsyncGeneratorWith` and
`testWrapAsyncGeneratorReportsParametersAfterBridge`.
`ClosureSerializationCycleTest.testAsyncClosureCyclesRejected` and
`testLegitimateAsyncClosuresRoundTrip` cover serialization.
`groovy.AsyncAwaitTest`, `groovy.lang.*Closure*`,
`org.apache.groovy.runtime.async.*` and `groovy.concurrent.*` pass. The
Checkstyle and CodeNarc gates pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]