PromiseFactory (Grails 3.1.7)
Date: 2016-05-19

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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