Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dbish6/async-delay-callback
A small dependency for asynchronous delays within your code! It also includes an optional callback that you can utilize.
https://github.com/dbish6/async-delay-callback
async delay dependency javascript jest npm npm-package promise promises typescript
Last synced: about 1 month ago
JSON representation
A small dependency for asynchronous delays within your code! It also includes an optional callback that you can utilize.
- Host: GitHub
- URL: https://github.com/dbish6/async-delay-callback
- Owner: dBish6
- License: mit
- Created: 2024-02-24T03:05:42.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-03-24T19:10:08.000Z (10 months ago)
- Last Synced: 2024-04-24T14:19:24.338Z (9 months ago)
- Topics: async, delay, dependency, javascript, jest, npm, npm-package, promise, promises, typescript
- Language: TypeScript
- Homepage:
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- License: LICENSE
Awesome Lists containing this project
README
# async-delay-callback
A small utility for asynchronous delays within your code! It also includes an optional callback that you can utilize.
## Installation
This npm package seamlessly integrates with front-end environments and frameworks, including Vanilla, Vue, React, and more.```
$ npm i async-delay-callback
```## Examples
These are a few common use cases. The package is flexible and not restricted to these examples.### React
```
import { useState, useEffect } from "react";
import { delay } from "async-delay-callback";const delayExample = (children) => {
const [loading, setLoading] = useState({ percentage: 0, complete: false });useEffect(() => {
(async () => {
await delay(2000); // Delay without a callback.
console.log("loading", loading)
await delay(500, () => {
setLoading({ percentage: 50, complete: false });// ...Something being loaded in.
});
console.log("loading", loading)await delay(1000, () => {
setLoading({ percentage: 100, complete: true });// ...Something being loaded in.
});
console.log("loading", loading)
})();
}, []);// Renders main content after resources/features or whatever you're loading is loaded.
return loading.complete && {children};
};export default delayExample;
```### Other
```
const { delay } = require("async-delay-callback");delay(500, () => code being delayed.);
```## Contributing
Contributions are welcome! Although I'd like to keep this package as small as possible since it is meant to be a small utility.### To Get Started
- Fork this repository.
- Create a new branch.
- install the dependencies with `npm install`.
- Do a `npm run test` to see if you're all set.
- For the dev environment, `npm run dev` and there you go!```
$ npm install
$ npm run test
$ npm run dev
```## License
This project is licensed under the [MIT](https://github.com/dBish6/async-delay-callback/blob/master/LICENSE) License.## Support Me
If you find this package helpful consider buying me a coffee, your support helps me stay motivated!