/pTimeout

Primary LanguageTypeScriptMIT LicenseMIT

⌛ pTimeout

NPM version NPM downloads Build status Dependencies Coverage Status

Set a limit on promise execution time. Written in TypeScript, compiled down to ES2017 for use in any Node.js >=10.x!

💾 Installation

The package is on the NPM registry as @lolpants/ptimeout. Simply install it with your NPM client of choice.

🔧 Usage

// Import (CommonJS)
const pTimeout = require('@lolpants/ptimeout')

// Import (ESM)
import pTimeout from '@lolpants/ptimeout'

// Use
const longPromise = () => new Promise(/* something that takes ages */)
await pTimeout(() => longPromise(), 1000 * 10)
// Will throw an error if timeout takes longer than 10s