Skip to content

arndesk/awaitdelay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


@arndesk/awaitdelay

A Node Js utility to add timeouts to promises

Get StartedInstallationUsageFeaturesContributingLicense

Get Started

Installation

Use npm to install this package:

npm install @arndesk/awaitdelay

Usage

Here's a basic example of how to use awaitdelay in your code:


// ES Modules import
import awaitdelay from '@arndesk/awaitdelay';
// CommonJS require
const awaitdelay = require('@arndesk/awaitdelay');

// Async function to use the awaitdelay function
async function main() {
  const slowPromise = new Promise(resolve => setTimeout(() => resolve('Resolved'), 5000));

  try {
    const result = await awaitdelay(slowPromise, { timeout: 5000 }); // 5 seconds timeout
    console.log(result);
  } catch (error) {
    console.error(error.message);
  }
}

main();

Features

  • Provides a straightforward way to add timeouts to promises
  • Easily adjustable timeout duration
  • Compatible with both ES Modules and CommonJS
  • Useful in a wide range of JavaScript and TypeScript projects