interface IScriptingSite {
// Methods
${alert}(message: string): void;
${input}(message: string): string;
${async}(handler: () => void, ms: number, repetitive?: boolean): number;
${cancelAsync}(handlerId: number): void;
${loadTextFile}(path: string): string;
${delay}(ms: number): Promise<void>;
}
// This interface is not available in managed environment
// This interface is not available in native environment
alert(message: string): void;
// This method is not available in managed environment
// This method is not available in native environment
message
Prints the given string to the script console.
for (var i = 0; i < 100; i++)
alert("i equals to " + i + "\n");
input(message: string): string;
// This method is not available in managed environment
// This method is not available in native environment
message
The string entered by the user.
Displays a message to the user and asks him to enter the line of text. The method then returns the text returned by the user. The call to this method results in a message box to be displayed.
var name = input("Enter your name:");
alert("Hello, " + name);
async(handler: () => void, ms: number, repetitive?: boolean): number;
// This method is not available in managed environment
// This method is not available in native environment
handler
ms
milliseconds once or until cancelled, depending on the repetitive
parameter.ms
repetitive
Returns an asynchronous function identifier. You may pass this identifier to IScriptingSite.cancelAsync method to cancel delayed function.
Schedules a passed Javascript function for delayed execution. A caller may optionally specify if the async function should be repetitive.
TypeScript lambda that is executed once after 1 second:
async(() => alert("Async handler executed"), 1000);
JavaScript function that is invoked every 2 seconds until cancelled after 20 seconds:
var h1 = async(function() { alert("Async handler executed"); }, 2000, true);
async(function() { cancelAsync(h1); }, 20000);
cancelAsync(handlerId: number): void;
// This method is not available in managed environment
// This method is not available in native environment
handlerId
Cancels pending async handler.
JavaScript function that is invoked every 2 seconds until cancelled after 20 seconds
var h1 = async(function() { alert("Async handler executed"); }, 2000, true);
async(function() { cancelAsync(h1); }, 20000);
loadTextFile(path: string): string;
// This method is not available in managed environment
// This method is not available in native environment
path
Loads contents of a text file into a string.
Load text file into string and print it:
alert(loadTextFile("c:\\temp\\test.js"));
delay(ms: number): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
ms
Returns a promise that gets completed in a given number of milliseconds.
Using await:
async function test() {
// ...
await delay(500);
// ...
}
Using continuations:
delay(500).then(() => { ... });