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.
get-promisable-result
Advanced tools
A very small JavaScript utility to check and retry a function a limited number of times abstracting it in a Promise
A very small JavaScript utility to check and retry a function a limited number of times abstracting it in a Promise
npm install get-promisable-result
yarn add get-promisable-result
pnpm add get-promisable-result
getPromisableResult(
getResultFunction: () => T,
checkResult: (result: T) => boolean,
options: PromisableOptions = {}
): Promise<T>
getResultFunction
should be a function that returns something. This something is what you expect when the promise gets resolved.
checkResult
is a function that will have as a parameter the result of the getResultFunction
and it should return a boolean
to validate that the result is OK. If this function returns false
, the getResultFunction
will be executed a limited number of times (consult the options section) until its result pass the check or until it reached the retries
(consult the options section).
Parameter | Type | Default | Description |
---|---|---|---|
retries | number | 10 | number of retries that will be performed before the promise rejects |
delay | number | 10 | delay between the retries |
shouldReject | boolean | true | indicates if the promise should be rejected when the number of retries reached the limit. If this parameter is set to false and the number of retries is reached the Promise will be resolved with the last value returned by getResultFunction |
rejectMessage | string | ** | custom error message. It can contain the substring {{ retries }} and it will be replaced with the number of retries |
** The default
rejectMessage
will beCould not get the result after {{ retries }} retries
Querying a DOM element that is rendered asynchronously with a custom retries
, delay
and rejectMessage
getPromisableResult(
() => document.getElementById('my-element'),
(element) => element !== null,
{
retries: 50,
delay: 100,
rejectMessage: 'My element could not be retrieved after {{ restries }} retries'
}
)
.then((element) => {
// Do something with the element
})
.catch((error) => {
// Do something if the promise is rejected
// My element could not be retrieved after 50 retries
});
FAQs
A very small JavaScript utility to check and retry a function a limited number of times abstracting it in a Promise
The npm package get-promisable-result receives a total of 17 weekly downloads. As such, get-promisable-result popularity was classified as not popular.
We found that get-promisable-result demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.