Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lazybird

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazybird

Lazy promises with Bluebird

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

lazybird

Lazy promises using Bluebird.

Why?

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');
        
      });
  });

How?

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).

Example

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

Keywords

FAQs

Package last updated on 05 Dec 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc