Skip to content
graemerocher edited this page Mar 5, 2013 · 3 revisions

GORM Async API

Callbacks

Book.list() { results ->

}

Promises

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 ->

}

DetachedCriteria

def query1 = Book.where {
  title == "foo"
}
def query2 = Book.where {
  title == "foo"
}

whenDone(query1, query2, query3) { results ->

}

Controllers Abstraction

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
}
Clone this wiki locally