Package: grails.async

## [Groovy] 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 Params | Return Type | Name and description
    --- | --- | ---
    `` | `void` | `addPromiseDecoratorLookupStrategy(PromiseDecoratorLookupStrategy lookupStrategy)` Adds a PromiseDecoratorLookupStrategy.
    `<T>` | `groovy.lang.Closure<T>` | `applyDecorators(groovy.lang.Closure<T> c, java.util.List<PromiseDecorator> decorators)` Applies the registered decorators to the given closure
    `<T>` | `Promise<T>` | `createBoundPromise(T value)` Creates a promise with a value pre-bound to it
    `<T>` | `Promise<T>` | `createPromise(java.lang.Class<T> returnType)` Creates an unfulfilled promise that returns the given type
    `` | `Promise<java.lang.Object>` | `createPromise()` Creates an unfulfilled promise that returns void
    `<K, V>` | `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
    `<K, V>` | `Promise<java.util.Map<K, V>>` | `createPromise(java.util.Map<K, V> map, java.util.List<PromiseDecorator> decorators)` Creates a promise from the given map where the values of the map are either closures or Promise instances
    `<T>` | `Promise<java.util.List<T>>` | `createPromise(Promise<T>... promises)` Creates a promise from one or more other promises
    `<T>` | `Promise<T>` | `createPromise(groovy.lang.Closure<T>... c)` Creates a promise from one or many closures
    `<T>` | `Promise<T>` | `createPromise(groovy.lang.Closure<T> c, java.util.List<PromiseDecorator> decorators)` Creates a promise from one or many closures
    `<T>` | `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
    `<T>` | `Promise<java.util.List<T>>` | `createPromise(java.util.List<groovy.lang.Closure<T>> closures)` Creates a promise from one or many closures
    `<T>` | `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
    `<T>` | `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
    `<T>` | `java.util.List<T>` | `waitAll(Promise<T>... promises)` Synchronously waits for all promises to complete returning a list of values
    `<T>` | `java.util.List<T>` | `waitAll(java.util.List<Promise<T>> promises)` Synchronously waits for all promises to complete returning a list of values
    `<T>` | `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

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

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

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

    - #### <T> Promise<T> createPromise(java.lang.Class<T> returnType)

      Creates an unfulfilled promise that returns the given type

      Parameters:
        `returnType` - The return type
        `` - The type of the class
      Returns:
        The unfulfilled promise

    - #### Promise<java.lang.Object> createPromise()

      Creates an unfulfilled promise that returns void

      Returns:
        The unfulfilled promise

    - #### <K, V> 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

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

      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

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

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

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

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

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

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

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

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

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

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