[Helma-dev] app.invoke() and app.invokeAsync()

Hannes Wallnoefer hannesw at gmail.com
Wed Mar 28 22:36:31 CEST 2007


Hi there,

I just committed two very cool new features called app.invoke() and
app.invokeAsync(). Both come in two variants:

app.invoke(thisObject, functionOrFunctionName, argsArray);
app.invoke(thisObject, functionOrFunctionName, argsArray, timeoutInMillis);

Both invoke() and invokeAsync() run the function in a new evaluator,
but invoke() waits for the function to return, while invokeAsync
immediately returns a handle that allows to track the function call
through these properties:

  running - true while the function is running, false afterwards
  result - the value returned by the function, if any
  exception - the exception thrown by the function, if any

If no timeout is specified, default timeout for invoke() is 30
seconds, while for invokeAsync() the default timeout is 15 minutes.

I probably forgot something. Never mind, I'll write it up tomorrow.
Here's a simple example of invokeAsync() to start experimenting:

function test_async_action() {
    var func = function(name) {
        for (var i = 0; i < 5; i++) {
            java.lang.Thread.sleep(1000);
            writeln("HALLO " + name + "!");
        }
        return "HALLO " + name;
    };
    var handle = app.invokeAsync(this, func, ["FRITZ"], 10000);
    res.writeln(handle);
    java.lang.Thread.sleep(6000);
    res.writeln(handle);
}

hannes


More information about the Helma-dev mailing list