grails.async.Promises Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grails-async Show documentation
Show all versions of grails-async Show documentation
Grails Web Application Framework
/*
* Copyright 2013 SpringSource
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package grails.async;
import groovy.lang.Closure;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.grails.async.decorator.PromiseDecorator;
import org.grails.async.factory.SynchronousPromiseFactory;
import org.grails.async.factory.gpars.GparsPromiseFactory;
/**
* Factory class for working with {@link Promise} instances
*
* @author Graeme Rocher
* @since 2.3
*/
public class Promises {
static PromiseFactory promiseFactory;
static {
if (GparsPromiseFactory.isGparsAvailable()) {
promiseFactory = new GparsPromiseFactory();
}
/*else if (ReactorPromiseFactory.isReactorAvailable()) {
promiseFactory = new ReactorPromiseFactory()
}*/
else {
promiseFactory = new SynchronousPromiseFactory();
}
}
public static PromiseFactory getPromiseFactory() {
if (promiseFactory == null) {
if (GparsPromiseFactory.isGparsAvailable()) {
promiseFactory = new GparsPromiseFactory();
}
else {
promiseFactory = new SynchronousPromiseFactory();
}
}
return promiseFactory;
}
public static void setPromiseFactory(PromiseFactory promiseFactory) {
Promises.promiseFactory = promiseFactory;
}
/**
* @see PromiseFactory#waitAll(grails.async.Promise[])
*/
public static List waitAll(Promise...promises) {
return getPromiseFactory().waitAll(promises);
}
/**
* @see PromiseFactory#waitAll(java.util.List)
*/
public static List waitAll(List> promises) {
return getPromiseFactory().waitAll(promises);
}
/**
* @see PromiseFactory#waitAll(java.util.List)
*/
public static List waitAll(List> promises, final long timeout, final TimeUnit units) {
return getPromiseFactory().waitAll(promises, timeout, units);
}
/**
* @see PromiseFactory#onComplete(java.util.List, groovy.lang.Closure)
*/
public static Promise> onComplete(List> promises, Closure> callable ) {
return getPromiseFactory().onComplete(promises, callable);
}
/**
* @see PromiseFactory#onError(java.util.List, groovy.lang.Closure)
*/
public static Promise> onError(List> promises, Closure> callable ) {
return getPromiseFactory().onError(promises, callable);
}
/**
* @see PromiseFactory#createPromise(java.util.Map)
*/
public static Promise
© 2015 - 2025 Weber Informatics LLC | Privacy Policy