Package: grails.async

## [Java] Interface PromiseFactory

- An interface capable of creating Promise instances. The Promises static methods use this interface to create promises. The default Promise creation mechanism can be overriden by setting Promises.setPromiseFactory

  Authors:
    Graeme Rocher
  Since:
    2.3

- - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `void` | `addPromiseDecoratorLookupStrategy(PromiseDecoratorLookupStrategy lookupStrategy)` Adds a PromiseDecoratorLookupStrategy.
    `groovy.lang.Closure<T>` | `applyDecorators(groovy.lang.Closure<T> c, java.util.List<PromiseDecorator> decorators)` Applies the registered decorators to the given closure
    `Promise<T>` | `createBoundPromise(T value)` Creates a promise with a value pre-bound to it
    `Promise<java.util.Map<K, V>>` | `createPromise(java.util.Map<K, V> map)` Creates a promise from the given map where the values of the map are either closures or Promise instances
    `Promise<java.util.List<T>>` | `createPromise(Promise<T>... promises)` Creates a promise from one or more other promises
    `Promise<T>` | `createPromise(groovy.lang.Closure<T>... c)` Creates a promise from one or many closures
    `Promise<T>` | `createPromise(groovy.lang.Closure<T> c, java.util.List<PromiseDecorator> decorators)` Creates a promise from one or many closures
    `Promise<java.util.List<T>>` | `createPromise(java.util.List<groovy.lang.Closure<T>> closures, java.util.List<PromiseDecorator> decorators)` Creates a promise from one or many closures
    `Promise<java.util.List<T>>` | `createPromise(java.util.List<groovy.lang.Closure<T>> closures)` Creates a promise from one or many closures
    `Promise<java.util.List<T>>` | `onComplete(java.util.List<Promise<T>> promises, groovy.lang.Closure<?> callable)` Executes the given callback when the list of promises completes
    `Promise<java.util.List<T>>` | `onError(java.util.List<Promise<T>> promises, groovy.lang.Closure<?> callable)` Executes the given callback if an error occurs for the list of promises
    `java.util.List<T>` | `waitAll(Promise<T>... promises)` Synchronously waits for all promises to complete returning a list of values
    `java.util.List<T>` | `waitAll(java.util.List<Promise<T>> promises)` Synchronously waits for all promises to complete returning a list of values
    `java.util.List<T>` | `waitAll(java.util.List<Promise<T>> promises, long timeout, java.util.concurrent.TimeUnit units)` Synchronously waits for all promises to complete returning a list of values

- - ### Method Detail

    - #### public void addPromiseDecoratorLookupStrategy(PromiseDecoratorLookupStrategy lookupStrategy)

      Adds a PromiseDecoratorLookupStrategy. The strategy implementation must be stateless, do not add a strategy that contains state

      Parameters:
        `lookupStrategy` - The lookup strategy

    - #### public groovy.lang.Closure<T> applyDecorators(groovy.lang.Closure<T> c, java.util.List<PromiseDecorator> decorators)

      Applies the registered decorators to the given closure

      Parameters:
        `c` - The closure
        `decorators` - The decorators
      Returns:
        The decorated closure

    - #### public Promise<T> createBoundPromise(T value)

      Creates a promise with a value pre-bound to it

      Parameters:
        `value` - The value
        `` - The type of the value
      Returns:
        A Promise

    - #### public Promise<java.util.Map<K, V>> createPromise(java.util.Map<K, V> map)

      Creates a promise from the given map where the values of the map are either closures or Promise instances

      Parameters:
        `map` - The map
      Returns:
        A promise

    - #### public Promise<java.util.List<T>> createPromise(Promise<T>... promises)

      Creates a promise from one or more other promises

      Parameters:
        `promises` - The promises
      Returns:
        The promise

    - #### public Promise<T> createPromise(groovy.lang.Closure<T>... c)

      Creates a promise from one or many closures

      Parameters:
        `c` - One or many closures
      Returns:
        A promise

    - #### public Promise<T> createPromise(groovy.lang.Closure<T> c, java.util.List<PromiseDecorator> decorators)

      Creates a promise from one or many closures

      Parameters:
        `c` - One or many closures
      Returns:
        A promise

    - #### public Promise<java.util.List<T>> createPromise(java.util.List<groovy.lang.Closure<T>> closures, java.util.List<PromiseDecorator> decorators)

      Creates a promise from one or many closures

      Parameters:
        `closures` - One or many closures
      Returns:
        A promise

    - #### public Promise<java.util.List<T>> createPromise(java.util.List<groovy.lang.Closure<T>> closures)

      Creates a promise from one or many closures

      Parameters:
        `closures` - One or many closures
      Returns:
        A promise

    - #### public Promise<java.util.List<T>> onComplete(java.util.List<Promise<T>> promises, groovy.lang.Closure<?> callable)

      Executes the given callback when the list of promises completes

      Parameters:
        `promises` - The promises
        `callable` - The callback to execute

    - #### public Promise<java.util.List<T>> onError(java.util.List<Promise<T>> promises, groovy.lang.Closure<?> callable)

      Executes the given callback if an error occurs for the list of promises

      Parameters:
        `promises` - The promises The promises
        `callable` - The error callback to execute

    - #### public java.util.List<T> waitAll(Promise<T>... promises)

      Synchronously waits for all promises to complete returning a list of values

      Parameters:
        `promises` - The promises
      Returns:
        The list of bound values

    - #### public java.util.List<T> waitAll(java.util.List<Promise<T>> promises)

      Synchronously waits for all promises to complete returning a list of values

      Parameters:
        `promises` - The promises
      Returns:
        The list of bound values

    - #### public java.util.List<T> waitAll(java.util.List<Promise<T>> promises, long timeout, java.util.concurrent.TimeUnit units)

      Synchronously waits for all promises to complete returning a list of values

      Parameters:
        `promises` - The promises
      Returns:
        The list of bound values