* </code>
* @throws ExecutionException
* @throws InterruptedException
*/
public static Future<Transaction> withTransaction(AsyncDatastoreService service, boolean crossGroup, Closure<?> c) throws InterruptedException, ExecutionException {
TransactionOptions opts = crossGroup ? TransactionOptions.Builder.withXG(true) : TransactionOptions.Builder.withDefaults();
Future<Transaction> transaction = service.beginTransaction(opts);
try {
// pass the transaction as single parameter of the closure
c.call(transaction);
// commit the transaction if the Closure<?> executed without throwing an exception