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.
Subscribe to:
Post Comments (Atom)
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...
-
The CodeHawks platform has an upcoming audit on the Sablier protocol, so I decided to read through the docs and familiarize myself with the...
-
The ZKasino project recently exit scammed over 33 million dollars worth of Ethereum. he recent debacle surrounding ZKasino offers valuable...
-
In addition to its native SDK, Hedera also supports smart contracts in a platform compatible with the Ethereum Virtual Machine. This allows ...
No comments:
Post a Comment