Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 8, 2024 via pnpm
Package summary
Share
0
issues
1
license
1
MIT
Package created
19 Jul 2012
Version published
21 May 2023
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
delay@6.0.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of delay 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does delay do?

The "delay" package is a useful tool in JavaScript programming which allows you to delay a promise for a specified amount of time. It is particularly useful when you need to manage asynchronous operations in your code, giving you more control over when certain actions should occur. The package is not limited to one-time delays; it can create promises that resolve after random amounts of time within a given range, which can be extremely beneficial in settings such as web scraping and performance tests where execution times can be unpredictable.

How do you use delay?

To use the "delay" package, you first need to install it using npm with the command npm install delay. After installation, you can import it into your JavaScript file using import delay from 'delay';. Below are some examples of how you can use it:

To delay a promise by 100 milliseconds:

import delay from 'delay';

bar();

await delay(100);

// This will be executed 100 milliseconds later
baz();

To delay a promise and resolve it with a specific value:

import delay from 'delay';

const result = await delay(100, {value: 'πŸ¦„'});

// This will be executed after 100 milliseconds and the result will be 'πŸ¦„'
console.log(result);

To abort the delay:

import delay from 'delay';

const abortController = new AbortController();

setTimeout(() => {
	abortController.abort();
}, 500);

try {
	await delay(1000, {signal: abortController.signal});
} catch (error) {
	// This will be executed 500 milliseconds later with the 'AbortError'
	console.log(error.name)
}

To clear the delay and immediately resolve the promise:

import delay, {clearDelay} from 'delay';

const delayedPromise = delay(1000, {value: 'Done'});

setTimeout(() => {
	clearDelay(delayedPromise);
}, 500);

// This will be executed 500 milliseconds later and the result will be 'Done'
console.log(await delayedPromise);

You can even create a custom delay instance using your own functions for setting and clearing timeout.

Where are the delay docs?

The documentation for the "delay" package can be found directly in its README on the GitHub page here. This includes detailed explanations of all the package's functions and options, as well as multiple usage examples for different scenarios.