Write a function named checkSettlesInTime
that receives 2 parameters:
maxTime
The function should return another Promise that will resolve with one of two values:
true
- if the received Promise settles before maxTime
milliseconds passedfalse
- if the received Promise takes longer than maxTime
milliseconds to settleNOTE: by settle we mean that the Promise is either resolved or rejected.
// A promise that resolves after 250ms
const promise1 = new Promise((resolve) => {
setTimeout(() => resolve(), 250);
});
// A promise that rejects after 2500ms
const promise2 = new Promise((_, reject) => {
setTimeout(() => reject(), 2500);
});
checkSettlesInTime(promise1, 500).then((didSettle) => {
console.log(didSettle); // should print "true"
});
checkSettlesInTime(promise2, 1000).then((didSettle) => {
console.log(didSettle); // should print "false"
});