
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
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.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.