CallbackSystem

class CallbackSystem

A mechanism for adapting a Java Function into an Avail A_Function. The Java function must take an A_Tuple and return an AvailObject. The Avail function's signature is provided, and will pack its arguments into a tuple for the Java function. The Java function's returned value will be checked at runtime before being returned into Avail.

If a Throwable is thrown by the Java code, it will be caught, wrapped as a pojo inside an Avail exception, and rethrown within Avail.

Note that the AvailRuntime that's responsible for the A_Fiber doing the callback contains a CallbackSystem whose callbackExecutor's worker threads are responsible for performing the callback to the Java lambda. Performing a long computation, significant wait, or unbounded blocking may negatively affect execution of other callbacks, so it's recommended that exceptionally long or blocking computations be performed in some other way.

Author

Mark van Gulik

Constructors

Link copied to clipboard
fun CallbackSystem()

Types

Link copied to clipboard
interface Callback

A mechanism for invoking Java lambdas from Avail.

Link copied to clipboard
interface CallbackCompletion

A mechanism for indicating when a callback Java lambda has completed successfully. By having a Callback invoke this when it's deemed complete instead of coupling it to the time that the lambda function invocation returns, the Java client is free to delegate the responsibility for completing the callback to other Java Threads, such as thread pools, completion mechanisms, coroutines, etc. Each CallbackCompletion must be invoked at most once, and mutually exclusively of the associated CallbackFailure.

Link copied to clipboard
interface CallbackFailure

A mechanism for indicating when a Java lambda has completed unsuccessfully. By having a Callback invoke this when it's deemed to have failed instead of coupling it to the time that the lambda function invocation returns or throws, the Java client is free to pass the responsibility for completing the callback to other Java Threads, such as thread pools, completion mechanisms, coroutines, etc. Each CallbackCompletion must be invoked at most once, and mutually exclusively of the associated CallbackFailure.

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun destroy()

Destroy all data structures used by this AvailRuntime. Also disassociate it from the current Thread's local storage.

Link copied to clipboard
fun executeCallbackTask(    callback: CallbackSystem.Callback,     argumentsTuple: A_Tuple,     completion: CallbackSystem.CallbackCompletion,     failure: CallbackSystem.CallbackFailure)

Schedule a Runnable task for eventual execution by the thread pool executor for callback operations. The implementation is free to run the task immediately or delay its execution arbitrarily. The task will not execute on an AvailThread.