
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
promise-reflect
Advanced tools
A simple function for use with Promise.all(...) that forces a promise to resolve, returning an object that indicates the actual promise status and the underlying object returned from the original promise.
A simple function that forces a promise to resolve, returning an object that indicates the actual promise status and the underlying object returned from the original promise.
//If underlying promise resolves
{
"data": {
//Object returned by underlying promise
},
"status":"resolved"
}
//If underlying promise rejects
{
"error": {
//Object returned by underlying promise
},
"status":"rejected"
}
The reason for this functionallity to to augment Promise.all(...) to allow for some promises to reject without losing the data returned from those that succeeded.
See the following StackOverflow post: http://stackoverflow.com/questions/31424561/wait-until-all-es6-promises-complete-even-rejected-promises
'use strict'
let promiseReflect = require('../promise-reflect');
let p1 = new Promise((resolve, reject) => {
setTimeout(resolve, 1000, "one");
});
let p2 = new Promise((resolve, reject) => {
setTimeout(resolve, 2000, "two");
});
let p3 = new Promise((resolve, reject) => {
setTimeout(resolve, 3000, "three");
});
let p4 = new Promise((resolve, reject) => {
setTimeout(resolve, 4000, "four");
});
let p5 = new Promise((resolve, reject) => {
reject("reject-one");
});
let p6 = new Promise((resolve, reject) => {
reject("reject-two");
});
let promisesArray = [p1, p2, p3, p4, p5, p6]
Promise.all(promisesArray.map(promiseReflect))
.then(values => {
let resolved = values.filter(value => value.status === 'resolved');
let rejected = values.filter(value => value.status === 'rejected');
console.log(`Values: ${JSON.stringify(values)}`);
console.log(`Resolved: ${JSON.stringify(resolved)}`);
console.log(`Rejected: ${JSON.stringify(rejected)}`);
})
.catch(reason => {
console.log(`Shouldn't get here as all promises resolve when put through promise-reflect`);
});
// Output
// Values: [{"data":"one","status":"resolved"},{"data":"two","status":"resolved"},{"data":"three","status":"resolved"},{"data":"four","status":"resolved"},{"error":"reject-one","status":"rejected"},{"error":"reject-two","status":"rejected"}]
// Resolved: [{"data":"one","status":"resolved"},{"data":"two","status":"resolved"},{"data":"three","status":"resolved"},{"data":"four","status":"resolved"}]
// Rejected: [{"error":"reject-one","status":"rejected"},{"error":"reject-two","status":"rejected"}]
##Credit The logic in this package is heavily based upon the question response by Benjamin Gruenbaum seen here: http://stackoverflow.com/a/31424853/3164844
FAQs
A simple function for use with Promise.all(...) that forces a promise to resolve, returning an object that indicates the actual promise status and the underlying object returned from the original promise.
The npm package promise-reflect receives a total of 1,729 weekly downloads. As such, promise-reflect popularity was classified as popular.
We found that promise-reflect 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.