Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is asynchronous call of JavaScript function possible in Windows Script Host?

Imagine you have a simple function in Windows Script Host (JScript) environment:

function say(text) {
    WScript.Sleep(5000);
    WScript.Echo(text);
}

Is it possible to call say() asynchronously?

Note: Such browser-based methods as setInterval() or setTimeout are not available in WSH.

like image 602
Savva Mikhalevski Avatar asked Sep 09 '26 13:09

Savva Mikhalevski


1 Answers

No, Windows Script Host doesn't support calling script functions asynchronously. You'll have to run two scripts simultaneously to achieve this effect:

// [main.js]
var oShell = new ActiveXObject("WScript.Shell");
oShell.Run(WScript.FullName + " say.js Hello");

WScript.Echo("Hello from main");

 

// [say.js]
WScript.Sleep(5000);
WScript.Echo(WScript.Arguments.Item(0));
like image 131
Helen Avatar answered Sep 12 '26 01:09

Helen