nope-js-browser
Version:
NoPE Runtime for the Browser. For nodejs please use nope-js-node
53 lines (52 loc) • 1.64 kB
JavaScript
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @desc [description]
*/
const _runningInNode = typeof process !== "undefined" &&
typeof process.release !== "undefined" &&
process.release.name === "node";
/**
* Function to call a function something direct async
*/
export const callImmediate = _runningInNode
? (callback, ...args) => {
// return setTimeout(callback, 0, ...args);
const trace = new Error("Error for Bugtracing");
return setImmediate(() => {
try {
callback(...args);
}
catch (error) {
console.error(error);
console.log("Trancing Bug with the Following Error");
console.error(trace);
}
});
}
: (callback, ...args) => {
const trace = new Error("Error for Bugtracing");
return setTimeout(() => {
try {
callback(...args);
}
catch (error) {
console.error(error);
console.log("Trancing Bug with the Following Error");
console.error(trace);
}
}, 0);
};
export const callDirect = (callback, ...args) => {
callback(...args);
};
export const RUNNINGINNODE = _runningInNode;
export const RUNNINGINWINDOWS = _runningInNode
? process.platform === "win32"
: false;
export const RUNNINGINLINUX = _runningInNode
? process.platform === "linux"
: false;
export const RUNNINGINOSX = _runningInNode
? process.platform === "darwin"
: false;