Tools for EventScripter

System function: setTimeout()

Description

setTimeout(function f [, number delay = 0 [, object ...]])

Starts a new thread by running a dummy batch file. This function works just like the original one, except that the delay argument is optional.

Example

// Trigger Required: "Interval"
// Options recommended: 10000ms, synchronous

require(JD_HOME + "/eventscripter/system/setTimeout.js");

function f(arr) {
    alert(arr.join(" "));
}

setTimeout(f, 5000, ["hello", "world"]);
alert("setTimeout() is not blocking!");

Sourcecode

JD_HOME/eventscripter/system/setTimeout.js
/*jslint browser */
/*global callAsync, sleep, JD_HOME */
function setTimeout() {
    "use strict";

    var args = [];
    Array.prototype.push.apply(args, arguments); // (...args) not working in jd2

    if (args.length === 0) {
        return;
    }

    var func = args.shift();
    var time = args.shift() || 0;

    callAsync(function() {
        sleep(time);
        func.apply(null, args);
    }, JD_HOME + "/eventscripter/system/bin/dummy.bat");
}
JD_HOME/eventscripter/system/bin/dummy.bat
@echo off
setlocal
set hmmm=hmmmmmm