Class IvyAsyncRunner

java.lang.Object
ch.ivyteam.util.threadcontext.IvyAsyncRunner

public class IvyAsyncRunner extends Object
Runs async code in the Ivy context which was active while the runner was created.
This allows the execution of code that runs against the ivy API in a any thread pool.

Sample:

//called within ivy context (e.g. Script Activity)
IvyAsyncRunner asyncRunner = new IvyAsyncRunner();
Callable<String> slowFunction = ()->SomeAPI.call("hello", 12, TimeUnit.SECONDS);
Future<String> asyncResult = Executors.newSingleThreadExecutor().submit(()->asyncRunner.run(slowFunction));
 

Since:
7.3.0
API:
This is a public API.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the runner.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    run(Runnable runnable)
     
    <T> T
    run(Callable<T> callable)
     
  • Constructor Details

    • IvyAsyncRunner

      public IvyAsyncRunner()
      Creates the runner. Stores the Ivy context on creation to re-use it later in the run(Callable).
      API:
      This public API is available in Java.
  • Method Details

    • run

      public <T> T run(Callable<T> callable) throws Exception
      Parameters:
      callable - code to be executed asynchronously
      Returns:
      result
      Throws:
      Exception
      API:
      This public API is available in Java.
    • run

      public void run(Runnable runnable)
      Parameters:
      runnable - code to be executed asynchronously
      API:
      This public API is available in Java.