---
# System prepended metadata

title: 2637. Promise Time Limit
tags: [JavaScript]

---

# [2637. Promise Time Limit](https://leetcode.com/problems/promise-time-limit/description/?envType=study-plan-v2&envId=30-days-of-javascript)
![image](https://hackmd.io/_uploads/SypQEgkB0.png)
![image](https://hackmd.io/_uploads/S1LN4x1BA.png)
![image](https://hackmd.io/_uploads/r1nNExkSC.png)

題目希望我們寫一個新的promise來與原本的promise使用Promise.race()去比較
回傳先reslove或reject的
```js
var timeLimit = function(fn, t) {
    return async function(...args) {
        const originPromise = fn(...args) ;
        const newPromise = new Promise((resolve, reject)=>{
        setTimeout(()=>{
            reject("Time Limit Exceeded")
        },t)
        })

    return Promise.race([newPromise,originPromise]);    
    }
    
};
```
