WrappedScript
com.jsmacrosce.jsmacros.core.library.impl.classes.WrappedScript
Wraps a script run as a MethodWrapper for Java callback interfaces. Calls that return a value wait for the script even when the wrapper is asynchronous; calls that return nothing wait only for synchronous wrappers. Synchronous calls start a lock watchdog using the configured maximum lock time; if the lock remains held past that limit, the script context is closed.
The one-argument accept(Object) method passes an existing BaseEvent through;
other forms create an EventWrappedScript payload.
// Pass the wrapper to a Java API that accepts a callback.
const wrapper = JsMacros.wrapScriptRun("adder.js");
// Async wrappers skip waiting only for callbacks with no return value.
const later = JsMacros.wrapScriptRunAsync("adder.js");In the wrapped target script adder.js, a two-argument callback supplies arg1 and arg2 through its EventWrappedScript payload:
event.setReturnDouble(Number(event.arg1) + Number(event.arg2));Type Parameters
T: the type the first argument arrives asU: the type the second argument arrives as, andnullunless the wrapper was passed as a two argument interfaceV: the type of the value the script returns to the caller
Constructors
new WrappedScript
new WrappedScript(Core<?, ?> runner, Function<BaseEvent, EventContainer<BaseScriptContext<?>>> f, boolean _async)#Parameters:
runner: core used to create events and handle synchronous-call waitingf: function invoked with the event to start the run and return its container for waiting_async: whether void-returning callbacks skip waiting; value-returning callbacks wait regardless
Fields
_async
f
Methods
accept
accept(T t): void#arg1 of an EventWrappedScript. The call waits unless this wrapper is asynchronous.Parameters:
t: the argument to pass to the script, and the value ofarg1unless it is already an event
accept(T t, U u): void#t as arg1 and u as arg2, discarding its result. Unlike accept, this always creates an EventWrappedScript. The call waits unless this wrapper is asynchronous.Parameters:
t: the first argument, which the script reads asarg1u: the second argument, which the script reads asarg2
apply
apply(T t): V#t as arg1 and arg2 set to null, then returns the event's result unchanged. Unlike accept, it always creates an EventWrappedScript; it waits even when _async is set.Parameters:
t: the argument to pass to the script, which the script reads asarg1
null if none was setapply(T t, U u): V#t as arg1 and u as arg2, then returns the event's result unchanged. It waits even when _async is set.Parameters:
t: the first argument, which the script reads asarg1u: the second argument, which the script reads asarg2
null if none was setcompare
compare(T o1, T o2): int#o1 as arg1 and arg2 set to null; the comparator's second value, o2, is not passed to the script. The result is cast to Integer, and the call waits even when _async is set. A non-Integer result, including null, causes a ClassCastException.Parameters:
o1: the first of the two values, which the script reads asarg1o2: the second of the two values, which is not passed on to the script
null fails here as wellget
get(): V#arg1 and arg2 set to null, then returns its result unchanged. The call waits even when _async is set.null unless the script set itrun
run(): void#arg1 and arg2 set to null; its result is discarded. The caller waits unless _async is set.test
test(T t): boolean#t as arg1 and arg2 set to null, then casts the result to Boolean. It waits even when _async is set; a non-Boolean result, including null, causes a ClassCastException.Parameters:
t: the argument to pass to the script, which the script reads asarg1
test(T t, U u): boolean#t as arg1 and u as arg2, then casts its result to Boolean. The call waits even when _async is set; a non-Boolean result, including null, causes a ClassCastException.Parameters:
t: the first argument, which the script reads asarg1u: the second argument, which the script reads asarg2
null fails here as well