Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
typescript-async-timeouts
Advanced tools
$ npm install typescript-async-timeouts --save
or
$ yarn add typescript-async-timeouts
Too many times we have to manage the timeouts. Keeping the timeout result somewhere and managing to clean it up. Aswell providing asynchronous method and keeping the promises increases the boulerplate. To solve this there are two methods:
cancel()
to cancel the timeoutSo, instead of:
try {
let timeout = null;
const result = await new Promise((resolve, reject) => {
timeout = setTimeout(() => async () => {
try {
const result = await myAsyncCall();
resolve(result);
} catch (error) {
reject(error);
}
}, 1)
});
// when we would like to cancel
if (timeout != null) {
clearTimeout(timeout)
}
} catch (error) {
concole.error(error);
}
We could run
try {
const result = runAsyncLater(myAsyncCall, 1)
result.cancel(); // to cancel the result
await result; // to get the result
} catch (error) {
console.error(error);
}
Short, right? Also, there is a ashortcut to synchronous call
try {
const result = runLater(() => { return "OK"; }, 1);
result.cancel(); // to cancel the result
await result; // to get the result
} catch (error) {
console.error(error);
}
I have really long array to iterate or heavy logic which needs to be run on ech row and I would not like to block the browser, So, there is a way to iterate asynchronous way. With two methods:
To solve the problem there are two methods:
(value: ValueType, index: number, cancel: () => void) => Promise<any>
(value: ValueType, index: number, cancel: () => void) => any
Basic syntax:
const runnable = iterateAsyncLater([...long_array], async (value, index, cancel) => {
// do some magic stuff or call cancel();
});
runnable.cancel() // If I decied not to go this way
await runnable; // to wait until it runs
Or when the run is not async
const runnable = iterateLater([...long_array], (value, index, cancel) => {
// do some magic stuff or call cancel();
});
runnable.cancel() // If I decied not to go this way
await runnable; // to wait until it runs
FAQs
Typescript future timeout utils
We found that typescript-async-timeouts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.