Get Started • Installation • Usage • Features • Contributing • License
Use npm
to install this package:
npm install @arndesk/awaitdelay
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();
- 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