- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 966
 
Async Proposal
        graemerocher edited this page Mar 5, 2013 
        ·
        3 revisions
      
    Book.list() { results ->
}
def promise1 = Book.async.list()
def promise2 = Book.async.list()
def promise3 = Book.async.list()
whenDone(promise1, promise2, promise3) { results ->
}
whenDone(promise1, promise2, promise3).then { results ->
}, { error ->
}
def query1 = Book.where {
  title == "foo"
}
def query2 = Book.where {
  title == "foo"
}
whenDone(query1, query2, query3) { results ->
}
def doStuff() {
   return { // return a closure
     // long running task
   }
}
def list() {
    // return closures as model values, executed asynchronously
    [books: { Book.list() }, count: { Book.count() } ]
}
// gpars integration
def hardwork() {
    final polish = ...
    final transform = ...
    final save = ...
    final notify = ...
    Promise promiseForStuff = task {
        loadStuffFromDB()
    }
    promiseForStuff.then polish then transform then save
    [stuff: promiseForStuff] // return model values as promises
}