Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imrandil/promise_javascript_reloaded_real_world_example
promise javascript leet code practice question into real world like implementation
https://github.com/imrandil/promise_javascript_reloaded_real_world_example
grinding javascript leetcode promise real-world-problem-solving
Last synced: 7 days ago
JSON representation
promise javascript leet code practice question into real world like implementation
- Host: GitHub
- URL: https://github.com/imrandil/promise_javascript_reloaded_real_world_example
- Owner: IMRANDIL
- Created: 2024-04-13T00:11:09.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-04-13T13:55:16.000Z (9 months ago)
- Last Synced: 2024-04-14T00:02:22.857Z (9 months ago)
- Topics: grinding, javascript, leetcode, promise, real-world-problem-solving
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Time Limit Function (One of the code blocks)
This function is designed to limit the execution time of another function. It wraps the provided function with a time limit, ensuring that it does not exceed a specified duration.
## Usage
```javascript
/**
* Creates a time-limited version of a function.
* @param {Function} fn - The function to be time-limited.
* @param {number} t - The time limit in milliseconds.
* @returns {Function} - The time-limited function.
*/
var timeLimit = function(fn, t) {
return async function(...args) {
const originalFnPromise = fn(...args);const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => {
reject('Time Limit Exceeded');
}, t);
});return Promise.race([originalFnPromise, timeoutPromise]);
};
};