Socket
Socket
Sign inDemoInstall

function-timeout

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

function-timeout - npm Package Compare versions

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"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc