SSJS serves as a string that is called upon when a method is invoked. There is no timing functionality incorporated within SSJS engine as it simply executes during the request and must finish once the request is completed.
When utilizing these functions in a browser or runtime like node.js, your code has the ability to operate in the background since the runtime remains active even after a request is fulfilled.
Consider this scenario: In order to halt a setTimeout function, you need to utilize clearInterval and store the reference to the timer in a variable. How can this variable be stored in SSJS?
UPDATE:
You have the option of modifying the DemoExecutor class to obtain access to the SSJS Interpreter.
class DemoCallable implements Callable {
private final NSFComponentModule module;
private transient JavaScriptInterpreter jsInterpreter;
private transient FBSGlobalObject globalObject;
public DemoCallable(NSFComponentModule module, JavaScriptInterpreter jsInterpreter, FBSGlobalObject globalObject ) {
this.module = module;
this.jsInterpreter = jsInterpreter;
this.globalObject = globalObject;
}
...
}
This grants you entry to the Interpreter and the global JS Object.
You are able to retrieve the objects from view root:
facesContext.getViewRoot().getGlobalObject()
facesContext.getViewRoot().getJSInterpreter()