Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@alius/timeout-promise
Advanced tools
Extension of Promise class with timeout capability.
npm install @alius/timeout-promise
Constructor accepts two parameters (optional): executor and timeout.
import { TimeoutPromise } from "@alius/timeout-promise";
const tp = new TimeoutPromise((resolve, reject) => {
// for example connecting to database
}, 100);
// if connection was not acquired within 100ms - promise will be rejected
tp.then(
conn => {
console.log("connected");
}
).catch(
err => {
console.log("failed to connect");
}
);
You can defer executor function by creating new TimeoutPromise
and later provide executor function to execute()
.
import { TimeoutPromise } from "@alius/timeout-promise";
const tp = new TimeoutPromise();
tp.then(
value => {
console.log(`Got value ${value}`);
}
).catch(
err => {
console.log(`Got error ${err}`);
}
);
tp.execute((resolve, reject) => {
resolve("Defered executor completed");
});
You can use TimeoutPromise
as semaphore.
import { TimeoutPromise } from "@alius/timeout-promise";
const tp = new TimeoutPromise();
tp.then(
value => {
console.log(`Got value ${value}`);
},
err => {
console.log(`Got error ${err}`);
}
);
if (someCondition) {
tp.resolve("Ok");
} else {
tp.reject("Not ok");
}
TimeoutPromise()
Creates new promise with defered execution.
TimeoutPromise(executor)
Creates normal promise.
TimeoutPromise(timeout)
Creates new promise with defered execution and timeout. If promise is not settled within specified amount of millisecons it will be rejected.
TimeoutPromise(executor, timeout)
Creates new promise with timeout. If promise is not settled within specified amount of millisecons it will be rejected.
state
Possible states:
resolve()
nor reject()
has been called yetresolve()
was called with other thenable (other promise) and waiting for that thenable to resolvesettled
Returns true
if promise is either fulfulled or rejected
value
If promise has been resolved - value;
otherwise - undefined
error
If promise has been rejected - error;
otherwise - undefined
execute(executor)
Executes specified executor function. Function will be executed only if promise state is either READY or PENDING.
resolve(value)
Resolves promise with specified value if promise state is either READY or PENDING.
reject(err)
Rejects promise with specified error if promise state is either READY or PENDING.
FAQs
Extended promise with timeout capability
We found that @alius/timeout-promise 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.