Class Callback


  • public class Callback
    extends java.lang.Object
    This class represents a JavaScript callback function. Callbacks can either be plain JavaScript functions, in which case they are invoked in their original worker, or an object containing properties called `module` and `name` specifying a function with the given name exported by the given module, in which case it can be invoked on any worker.
    • Constructor Summary

      Constructors 
      Constructor Description
      Callback​(org.mozilla.javascript.Scriptable function, RhinoEngine engine, boolean sync)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equalsCallback​(org.mozilla.javascript.Scriptable callback)
      Tests whether the argument is a callback and represents the same function as this callback.
      java.lang.Object invoke​(java.lang.Object... args)
      Invokes the callback with the given arguments, returning the return value or a future depending on whether this Callback is synchronous or not.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Callback

        public Callback​(org.mozilla.javascript.Scriptable function,
                        RhinoEngine engine,
                        boolean sync)
        Parameters:
        function - either a JavaScript function or a JavaScript object containing properties called `module` and `name` specifying a function exported by a RingoJS module.
        engine - the RhinoEngine instance
        sync - whether to invoke the callback synchronously (on the current thread) or asynchronously (on the worker's event loop thread)
    • Method Detail

      • equalsCallback

        public boolean equalsCallback​(org.mozilla.javascript.Scriptable callback)
        Tests whether the argument is a callback and represents the same function as this callback.
        Parameters:
        callback - a JavaScript function or object
        Returns:
        true if the callbacks represent the same function.
      • invoke

        public java.lang.Object invoke​(java.lang.Object... args)
        Invokes the callback with the given arguments, returning the return value or a future depending on whether this Callback is synchronous or not.
        Parameters:
        args - arguments to pass to the callback.
        Returns:
        the result if the callback is synchronous, or a Future that will resolve to the invocation in case it is an asynchronous callback.