infinity¶
Provides system-level information and functionality as well as script inclusion, module loading, process delaying and error reporting possibilities.
Module: none (built-in)
Besides the members listed below, the following namespaces are always available without infinity.loadModule(): infinity.current, infinity.os, infinity.lock, infinity.event, infinity.fileMode and infinity.encoding (enum and toString()/convert()). All other namespaces have to be loaded with loadModule().
stringArray¶
Extends: Array<string>
An array of strings.
beep()¶
Plays a notifying system sound.
Signature:
beep(): void
Example:
infinity.beep();
gc()¶
Triggers the garbage collector.
Signature:
gc(): void
Example:
infinity.gc();
getArgs()¶
Returns the command line arguments, which the INFINITY.JS executable file has been started with (without the name of the executable itself, but including switches like -console and the script file name).
Signature:
getArgs(): stringArray
Return type: stringArray
Example:
let x = infinity.getArgs();
getGlobal()¶
Returns the value of the specified global variable.
Signature:
getGlobal( name: string ): any
Parameters:
- name:
stringThe name of the global variable.
Return type: any
Example:
let value = infinity.getGlobal(name);
include()¶
Includes the specified script file and executes its contents at the position include() has been called. Each file is only included once per runtime: further calls for the same file are ignored (since 3.11 also with another spelling of the path, e.g. a/../b.js or, on Windows, other upper/lower case). Compile and runtime errors of the included file are thrown as errors; a file that failed is included again by the next call (before 3.11 the next call was silently ignored). While the included file is executed, infinity.current.dir and infinity.current.file refer to it.
Signature:
include( fileName: string ): void
Parameters:
- fileName:
stringThe name of the file to be included, relative to the program's root folder (
infinity.current.root, the folder containing the main script, usually thejsoutput folder inside the project folder), not relative to the including file. Absolute paths are supported since 3.11. Keep in mind that output files with the ending.jsshould be referenced.
Example:
infinity.include('includeTest.js');
loadModule()¶
Loads the specified INFINITY.JS module, making its functionality usable for the current runtime. Modules have to be loaded in every runtime that uses them (e.g. also inside thread scripts). Loading a module that is already loaded has no effect. Throws an error (Module ... not found) if the module does not exist.
Signature:
loadModule( moduleName: string ): void
Parameters:
- moduleName:
stringThe identifier of the module to be loaded (case-sensitive), e.g.
'infinity.http','infinity.database','infinity.crypto','infinity.memory','infinity.thread','infinity.date','infinity.process','infinity.scheduler'or'infinity.service', or the namespace of a native extension.
Example:
infinity.loadModule('infinity.http');
sendSentryEvent()¶
INFINITY.JS supports error reporting to the remote error monitoring service sentry.io. Settings like the DSN as well as the HandleNativeExceptions, HandleRuntimeExceptions and HandleScriptExceptions flags have to be placed inside the [Sentry] - block of your .ini configuration file in the folder containing the used INFINITY.JS executable file. sendSentryEvent() only sends the message if HandleScriptExceptions is enabled; otherwise the call has no effect.
Signature:
sendSentryEvent( message: string, level?: string, processInfo?: boolean ): void
Parameters:
-
message:
stringThe error message to be sent to
sentry.io. -
level:
string, optionalThe Sentry event level, which is sent as the
levelfield of the event (e.g.'error','warning'or'info'). Default:'error'(before 3.11 the string'undefined'was sent if omitted). -
processInfo:
boolean, optionalSpecifies whether additional technical data (e.g. runtime count, architecture, platform) should be sent with the message as tags.
Example:
infinity.sendSentryEvent('Error 123', 'error', true);
ini-file:
[Sentry]
HandleNativeExceptions=0
HandleRuntimeExceptions=0
HandleScriptExceptions=1
DSN="https://public@sentry.example.com/1"
sleep()¶
Delays the further execution of the current thread for the specified amount of milliseconds. Negative values are treated as 0. The sleep cannot be interrupted, so keep the delay short in loops that check terminated or threadTerminated.
Signature:
sleep( milliSeconds: number ): void
Parameters:
- milliSeconds:
numberThe amount of milliseconds for the delay.
Example:
infinity.sleep(1000);
//a 1-second delay
terminate()¶
Sets the infinity.terminated property for the running INFINITY.JS instance to true. This way, the message for process termination can be sent throughout multiple threads. terminate() does not stop the script by itself: the main program has to check infinity.terminated (e.g. in its main loop) and finish. When called inside a thread, scheduler task or HTTP handler script, the main program is terminated.
Optionally, an exit code can be passed, which the INFINITY.JS process returns when it ends (since 3.10.174). This can be used e.g. to let a service manager like systemd (Restart=on-failure) restart the process.
Signature:
terminate( exitCode?: number ): void
Parameters:
- exitCode:
number, optionalThe exit code of the INFINITY.JS process (integer). If omitted, the exit code is not changed.
Example:
console.debug(infinity.terminated);//false
infinity.terminate();
console.debug(infinity.terminated);//true
// request a restart by the service manager
infinity.terminate(75);
processEvents()¶
Executes the pending onTerminated callbacks of the infinity.thread objects created by the current runtime (in the main program, a thread script or a scheduler task) and, in the main thread of the process, pending synchronization requests of other threads. Call it regularly in the main loop of your program if you use such callbacks. Errors thrown by a callback are thrown by processEvents(). Since 3.11 it also works outside the main thread of the process (thread scripts and the main script of the Windows service, where it threw an error before and onTerminated callbacks were never called).
Signature:
processEvents(): void
Example:
while (!infinity.terminated) {
infinity.processEvents();
infinity.sleep(100);
}
terminated¶
Type: boolean
Indicates whether the INFINITY.JS instance is being terminated, either because infinity.terminate() has been called (in any runtime) or because the process has been asked to stop (e.g. Ctrl+C or a service stop). Inside threads and other sub-runtimes, the value of the main program is returned. Check this value in the main loop of your program and let it finish gracefully when the value is true.
Example:
while (!infinity.terminated) {
infinity.sleep(250);
}
threadTerminated¶
Type: boolean
Indicates whether the thread has been asked to terminate, i.e. stop() has been called on the infinity.thread object or the thread object is being released. This property only exists inside a script that is executed as a thread; in the main program it is undefined. Inside a thread, make sure that you check this value in your thread's main loop and let your thread terminate gracefully when the value is true.
Example:
// thread script
while (!infinity.threadTerminated) {
// do something
infinity.sleep(100);
}
version¶
Type: string
Returns the version string of the INFINITY.JS runtime (major, minor and build number, e.g. '3.21.316'). This is useful for logging, diagnostics, and ensuring compatibility with specific runtime versions. Since 3.10.174.
Example:
console.info('INFINITY.JS Version: ' + infinity.version);
// Output example: "INFINITY.JS Version: 3.21.316"
See Also: - Troubleshooting Guide - Collect diagnostic information
See Also: - Troubleshooting Guide - Collect diagnostic information