https://github.com/muke1908/promisewithtimeout
Early reject a promise with a timeout
https://github.com/muke1908/promisewithtimeout
Last synced: about 1 year ago
JSON representation
Early reject a promise with a timeout
- Host: GitHub
- URL: https://github.com/muke1908/promisewithtimeout
- Owner: muke1908
- License: mit
- Created: 2023-04-18T13:54:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T15:36:37.000Z (almost 3 years ago)
- Last Synced: 2025-02-01T19:45:03.170Z (about 1 year ago)
- Language: TypeScript
- Size: 11.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# promiseWithTimeout
Reject a promise early with timeout. In this example the promise will be rejected if the API doesn't return respose within 280ms.
```
const fetchProduct = fetch('https://fakestoreapi.com/products/1').then(res => res.json());
(async (){
try{
const products = await new PromiseWithTimeOut(fetchProduct, 280);
console.log({ products });
}catch(err){
console.log('err', err)
}
})()
```