Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tobysmith568/await-at-least
A small set of functions to await at least a certain amount of time before resolving a promise.
https://github.com/tobysmith568/await-at-least
await delay npm-package promise timeout
Last synced: 28 days ago
JSON representation
A small set of functions to await at least a certain amount of time before resolving a promise.
- Host: GitHub
- URL: https://github.com/tobysmith568/await-at-least
- Owner: tobysmith568
- License: isc
- Created: 2024-10-20T19:43:52.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-12-08T05:52:44.000Z (about 1 month ago)
- Last Synced: 2024-12-08T06:24:55.511Z (about 1 month ago)
- Topics: await, delay, npm-package, promise, timeout
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/await-at-least
- Size: 133 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# await-at-least
A small set of functions to await at least a certain amount of time before resolving a promise.
## Installation
```pwsh
npm install await-at-least
```## Usage
### awaitAtLeast
Wraps the given promise and makes sure it takes at least the given duration before it resolves or rejects.
```ts
import { awaitAtLeast } from "await-at-least";const postToServer = async (url: string, body: unknown) => {
// ...
};const responseFromServer = await awaitAtLeast(
800,
postToServer("https://api.example.com", requestBody)
);
```If the given promise resolves before the given amount of time is up, the returned promise will wait for the remaining time before returning the result.
If the given promise rejects before the given amount of time is up, the returned promise will wait for the remaining time before rethrowing the error.
### awaitAtLeastOrReject
Wraps the given promise and makes sure it takes at least the given duration before it resolves but will reject as soon as the wrapped promise rejects.
```ts
import { awaitAtLeastOrReject } from "await-at-least";const postToServer = async (url: string, body: unknown) => {
// ...
};const responseFromServer = await awaitAtLeastOrReject(
800,
postToServer("https://api.example.com", requestBody)
);
```If the given promise resolves before the given amount of time is up, the returned promise will wait for the remaining time before returning the result.
If the given promise rejects before the given amount of time is up, the returned promise will reject immediately.
## License
await-at-least is licensed under the [ISC license](./LICENSE.md).