2020-08-25 22:11:26 +00:00
|
|
|
/**
|
|
|
|
* @author Martin Karkowski
|
|
|
|
* @email m.karkowski@zema.de
|
|
|
|
* @create date 2020-08-25 14:52:52
|
2021-02-12 14:54:57 +00:00
|
|
|
* @modify date 2021-02-12 14:28:46
|
2020-08-25 22:11:26 +00:00
|
|
|
* @desc [description]
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare const process: any;
|
|
|
|
declare const setImmediate: any;
|
|
|
|
|
|
|
|
const _runningInNode = (
|
2021-02-12 14:54:57 +00:00
|
|
|
typeof process !== "undefined" &&
|
|
|
|
typeof process.release !== "undefined") && ((process as any).release.name === "node");
|
2020-08-25 22:11:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to call a function something direct async
|
|
|
|
*/
|
|
|
|
export const callImmediate = _runningInNode ? (callback: (...args) => void, ...args) => {
|
|
|
|
return setImmediate(() => {
|
|
|
|
try {
|
|
|
|
callback(...args);
|
|
|
|
} catch (error) {
|
2020-11-15 19:21:02 +00:00
|
|
|
console.error(error);
|
2020-08-25 22:11:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} : (callback: (...args) => void, ...args) => {
|
|
|
|
return setTimeout(callback, 0, ...args);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const callDirect = (callback: (...args) => void, ...args) => {
|
|
|
|
callback(...args);
|
|
|
|
};
|
|
|
|
|
2021-02-12 14:54:57 +00:00
|
|
|
export const RUNNINGINNODE = _runningInNode;
|
|
|
|
export const RUNNINGINWINDOWS = _runningInNode ? (require("os").type() != "Linux") : false;
|
|
|
|
export const RUNNINGINLINUX = _runningInNode ? (require("os").type() === "Linux") : false;
|