com.jogamp.common.util

## Class FunctionTask<R,A>

- java.lang.Object
- - com.jogamp.common.util.TaskBase
  - - com.jogamp.common.util.FunctionTask<R,A>

- All Implemented Interfaces:
    Function<R,A>, Runnable

      public class FunctionTask<R,A>
      extends TaskBase
      implements Function<R,A>

  Helper class to provide a Runnable queue implementation with a Runnable wrapper which notifies after execution for the `invokeAndWait()` semantics.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected A[]` | `args`
    `protected R` | `result`
    `protected Function<R,A>` | `runnable`

    - ### Fields inherited from class com.jogamp.common.util.TaskBase

      `attachment, catchExceptions, exceptionOut, isFlushed, runnableException, sourceStack, syncObject, tCreated, tExecuted, tStarted`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FunctionTask(Function<R,A> runnable, Object syncObject, boolean catchExceptions, PrintStream exceptionOut)` Create a RunnableTask object w/ synchronization, ie.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `R` | `eval(A... args)` Implementation may compute variable `args` list and returns a result.
    `R` | `getResult()` Retrieves the cached result of `run()` and is cleared within this method.
    `Function<R,A>` | `getRunnable()` Return the user action
    `static <U,V> U` | `invoke(boolean waitUntilDone, Function<U,V> func, V... args)` Invokes `func`.
    `void` | `run()`
    `void` | `setArgs(A... args)` Sets the arguments for `run()`.

    - ### Methods inherited from class com.jogamp.common.util.TaskBase

      `flush, getAttachment, getDurationInExec, getDurationInQueue, getDurationTotal, getExceptionOutIntro, getSyncObject, getThrowable, getTimestampAfterExec, getTimestampBeforeExec, getTimestampCreate, hasWaiter, isExecuted, isFlushed, isInQueue, printSourceTrace, setAttachment, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### runnable

          protected Function<R,A> runnable

    - #### result

          protected R result

    - #### args

          protected A[] args

  - ### Constructor Detail

    - #### FunctionTask

          public FunctionTask(Function<R,A> runnable,
                      Object syncObject,
                      boolean catchExceptions,
                      PrintStream exceptionOut)

      Create a RunnableTask object w/ synchronization, ie. suitable for `invokeAndWait()`.
      Parameters:
        `runnable` - the user action
        `syncObject` - the synchronization object the caller shall wait until `runnable` execution is completed, or `null` if waiting is not desired.
        `catchExceptions` - Influence an occurring exception during `runnable` execution. If `true`, the exception is silenced and can be retrieved via `TaskBase.getThrowable()`, otherwise the exception is thrown.
        `exceptionOut` - If not `null`, exceptions are written to this `PrintStream`.

  - ### Method Detail

    - #### invoke

          public static <U,V> U invoke(boolean waitUntilDone,
                       Function<U,V> func,
                       V... args)

      Invokes `func`.
      Parameters:
        `waitUntilDone` - if `true`, waits until `func` execution is completed, otherwise returns immediately.
        `func` - the `Function` to execute.
        `args` - the `Function` arguments
      Returns:
        the `Function` return value

    - #### getRunnable

          public final Function<R,A> getRunnable()

      Return the user action

    - #### setArgs

          public final void setArgs(A... args)

      Sets the arguments for `run()`. They will be cleared after calling `run()` or `eval(Object...)`.

    - #### getResult

          public final R getResult()

      Retrieves the cached result of `run()` and is cleared within this method.

    - #### run

          public final void run()

      Calls `eval(Object...)`.

      You may set the `eval(Object...)` arguments via `setArgs(Object...)` and retrieve the result via `getResult()`.

      Specified by:
        `run` in interface `Runnable`
      Specified by:
        `run` in class `TaskBase`

    - #### eval

          public final R eval(A... args)

      Description copied from interface: `Function`
      Implementation may compute variable `args` list and returns a result.
      Specified by:
        `eval` in interface `Function<R,A>`
      Parameters:
        `args` - variable argument list, `A[]`, maybe null
      Returns:
        the result.