Matthew,
I did some preliminary work on a continuation-based API for handling
sequences of dependent asynchronous operations (see [1]), which might
provide a starting point. It allows you to write code like:
async {
display("waiting for first result")
val result1 = callAsync(function1)
display("result1: " + result1)
val result2 = callAsync(function2(result1))
display("result2: " + result2)
val result3 = callAsync(function3(result2))
display("result3: " + result3)
}
It sounds like you want something that will allow you to send off
independent calls simultaneously and then combine their results, which
is not (yet) supported in this approach. I'd be interested in any
progress in that direction, though.
Here's an brief outline of my thoughts on how one could move this API
in that direction. Currently, callAsync makes a blocking call (from
the perspective of the code in the async block). That method could be
renamed 'blockingCall' or something, and a 'nonblockingCall' method
could be added that would return something like a future. Future
objects could be combined, and they would provide a 'waitFor' method
that would block (i.e., put the rest of the computation into a
continuation). So you could write code like:
async {
val future1 = nonblockingCall(fun1)
val future2 = nonblockingCall(fun2)
val future3 = nonblockingCall(fun3)
val results = (future1 ++ future2 ++ future3).waitFor
results match {
case (result1, result2, result3) =>
display("total:" + (result1 + result2 + result3))
}
}
~Aaron
[1]
https://github.com/anovstrup/scalagwt-sample/blob/progress-gwtdlx-hosted/src/com/google/gwt/sample/gwtdlx/client/Async.scala