function-timeout
Advanced tools
Comparing version 1.0.0 to 1.0.1
13
index.js
import vm from 'node:vm'; | ||
export default function functionTimeout(function_, {timeout} = {}) { | ||
const script = new vm.Script('returnValue = function_()'); | ||
const script = new vm.Script('returnValue = functionToRun()'); | ||
// TODO: Document the `context` option and add to types when I know it's something I want to keep. | ||
// If you use the `context` option, you do it at your own risk. | ||
export default function functionTimeout(function_, {timeout, context = vm.createContext()} = {}) { | ||
const wrappedFunction = (...arguments_) => { | ||
const context = { | ||
function_: () => function_(...arguments_), | ||
}; | ||
context.functionToRun = () => function_(...arguments_); | ||
script.runInNewContext(context, {timeout}); | ||
return context.returnValue; | ||
@@ -14,0 +13,0 @@ }; |
{ | ||
"name": "function-timeout", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Make a synchronous function have a timeout", | ||
@@ -19,2 +19,3 @@ "license": "MIT", | ||
}, | ||
"sideEffects": false, | ||
"engines": { | ||
@@ -21,0 +22,0 @@ "node": ">=18" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6114