2
votes

I found this example here Data Parallelism

GParsPool.withPool() {
    Closure longLastingCalculation = {calculate()}
    Closure fastCalculation = longLastingCalculation.async()
    Future result=fastCalculation()
    //do stuff while calculation performs …
    println result.get()
}

I find it a bit extensive. Is there a way to shorten it?
Maybe:

GParsPool.withPool() {
    Future result = calculate().async()
    //do stuff while calculation performs …
    println result.get()
}

Would that work?
If not, is there another way?

2

2 Answers

2
votes

Think you'd need:

Future result = { calculate() }.async()()
2
votes

calculate().async() will launch calculate method immediately. I'd bet with

GParsPool.withPool() {
    Future result = {calculate()}.async().call()
    //do stuff while calculation performs …
    println result.get()
}

because async() returns a closure. I'm not sure if ({calculate()}.async())() would be valid, i'll test that later