All Downloads are FREE. Search and download functionalities are using the official Maven repository.

grails.async.PromiseFactory Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
/*
 * 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.decorator.PromiseDecoratorLookupStrategy;

/**
 * An interface capable of creating {@link Promise} instances. The {@link Promises} static methods use this
 * interface to create promises. The default Promise creation mechanism can be overriden by setting {@link Promises#setPromiseFactory(PromiseFactory)}
 *
 * @author Graeme Rocher
 * @since 2.3
 */
public interface PromiseFactory {

    /**
     * Adds a PromiseDecoratorLookupStrategy. The strategy implementation must be stateless, do not add a strategy that contains state
     *
     * @param lookupStrategy The lookup strategy
     */
    void addPromiseDecoratorLookupStrategy(PromiseDecoratorLookupStrategy lookupStrategy);

    /**
     * Applies the registered decorators to the given closure
     * @param c The closure
     * @param decorators The decorators
     * @return The decorated closure
     */
     Closure applyDecorators(Closure c, List decorators);
    /**
     * Creates a promise with a value pre-bound to it
     * @param value The value
     * @param  The type of the value
     * @return A Promise
     */
     Promise createBoundPromise(T value);
    /**
     * Creates a promise from the given map where the values of the map are either closures or Promise instances
     *
     * @param map The map
     * @return A promise
     */
      Promise> createPromise(Map map);

    /**
     * Creates a promise from one or more other promises
     *
     * @param promises The promises
     * @return The promise
     */
     Promise> createPromise(Promise...promises);

    /**
     * Creates a promise from one or many closures
     *
     * @param c One or many closures
     * @return A promise
     */
     Promise createPromise(Closure... c);

    /**
     * Creates a promise from one or many closures
     *
     * @param c One or many closures
     * @return A promise
     */
     Promise createPromise(Closure c, List decorators);

    /**
     * Creates a promise from one or many closures
     *
     * @param closures One or many closures
     * @return A promise
     */
     Promise> createPromise(List> closures, List decorators);

    /**
     * Creates a promise from one or many closures
     *
     * @param closures One or many closures
     * @return A promise
     */
     Promise> createPromise(List> closures);

    /**
     * Synchronously waits for all promises to complete returning a list of values
     *
     * @param promises The promises
     * @return The list of bound values
     */
     List waitAll(Promise...promises);
    /**
     * Synchronously waits for all promises to complete returning a list of values
     *
     * @param promises The promises
     * @return The list of bound values
     */
     List waitAll(List> promises);

    /**
     * Synchronously waits for all promises to complete returning a list of values
     *
     * @param promises The promises
     * @return The list of bound values
     */
     List waitAll(List> promises, final long timeout, final TimeUnit units);

    /**
     * Executes the given callback when the list of promises completes
     *
     * @param promises The promises
     * @param callable The callback to execute
     */
     Promise> onComplete(List> promises, Closure callable);
    /**
     * Executes the given callback if an error occurs for the list of promises
     *
     * @param promises The promises The promises
     * @param callable The error callback to execute
     */
     Promise> onError(List> promises, Closure callable);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy