Wednesday, May 17, 2023

131: Function Timeout

 Today's challenge was to create a function that returns a timed out version of another function. Given a number of milliseconds, your function will either complete in time or it will return the string "Timeout Limit Exceeded". There are multiple ways to do this, but in the Leetcode editorial I learned about the very useful Promise.race() function. Promise.race accepts an array of promises, and it returns a promise that will resolve or reject with the first promise in the array to resolve or reject. Using this, the problem can be solved easily with a race between your function with its arguments, and a setTimeout function that rejects after the specified number of milliseconds. 

No comments:

Post a Comment

190: Sablier

 The CodeHawks platform has an upcoming audit on the Sablier protocol, so I decided to read through the docs and familiarize myself with the...