Delay the Resolution of Each Promise
Imagine you're building a system that needs to add artificial delays to promise-returning functions for rate limiting or throttling purposes. You have an array of functions that return promises, and you want to create a new array where each function introduces an additional delay before resolving or rejecting.
Your Task: Given an array functions and a delay duration ms, return a new array of functions. Each function in the new array should:
- Execute the corresponding original function
- Wait for the original promise to resolve or reject
- Add an additional delay of
msmilliseconds - Then resolve or reject with the same value/error
Think of it like adding a "cooldown period" to each promise, similar to how video games add cooldowns to abilities!
Input: An array of functions that return promises, and a delay duration in milliseconds
Output: A new array of functions that return delayed promises
Input & Output
Constraints
- 1 โค functions.length โค 1000
- 0 โค ms โค 104
- Each function in the input array returns a Promise
- The delay should be added after the original promise settles
- Preserve the original promise's resolution/rejection value and reason