Skip to content

muke1908/promiseWithTimeout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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<string>(fetchProduct, 280);
    console.log({ products });
  }catch(err){
    console.log('err', err)
  }
})()