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.
Lazy promises using Bluebird.
Lazybird allows you to create a promise that will only start resolving when you attach the first fulfilled or rejected handler. It "resolves lazily".
If promises are future values, then lazy promises are future values calculated on demand. Mostly this is useful to delay calculations that may never happen at all. You can create the promise, pass its reference around, but not bother to resolve it until the value or action is necessary.
Zombie uses lazy promises for its event loop. The promise only resolves when you ask it to.
For example:
// Click the "Edit" link, it will show delete link next to each item
return browser
.clickLink('#edit-items')
.then(function() {
// Waiting for the promise to resolve, as there's some
// animation and setTimeout involved
// Now click the delete link on one of these items
return browser
.clickLink('#delete-item-45')
.then(function() {
// Waiting for the promise to resolve, as it needs to
// make AJAX request to the server, wait for response
// Click the "Done" link to hide the delete links
//
// This method returns a promise but we don't care
// for the promise to resolve
browser.clickLink('#edit-done');
});
});
Just like any standard promise library, use Lazybird
to create a new promise
object and pass it the resolver callback. The only difference is, that resolved
function is not called until you ask the promise to resolve.
Since Lazybird
is based on Bluebird
, you get access to all the same methods
including then
, catch
, finally
, done
, reflect
, value
, etc).
const Lazybird = require('lazybird');
const lazy = new Lazybird(function(resolve) {
console.log('Resolving');
resolve();
});
console.log('Waiting ...');
setTimeout(function() {
console.log('5 seconds later ...');
lazy.then(function() {
console.log('Resolved');
});
}, 5000);
You will see:
Waiting ...
5 seconds later ...
Resolving
Resolved
FAQs
Lazy promises with Bluebird
We found that lazybird 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.