{"_id":"lazybird","_rev":"118881","name":"lazybird","description":"Lazy promises with Bluebird","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"assaf","email":"assaf@labnotes.org"}],"time":{"modified":"2021-06-03T10:54:36.000Z","created":"2014-12-05T22:08:43.517Z","1.0.0":"2014-12-05T22:08:43.517Z"},"users":{},"author":{"name":"Assaf Arkin","email":"assaf@labnotes.org","url":"http://labnotes.org/"},"repository":{"type":"git","url":"http://github.com/assaf/lazybird"},"versions":{"1.0.0":{"name":"lazybird","version":"1.0.0","description":"Lazy promises with Bluebird","homepage":"https://github.com/assaf/lazybird","author":{"name":"Assaf Arkin","email":"assaf@labnotes.org","url":"http://labnotes.org/"},"keywords":["lazy","promise"],"main":"index.js","scripts":{"prepublish":"mocha","test":"mocha"},"engines":{"node":"0.10.x"},"dependencies":{"bluebird":"2.x.x"},"repository":{"type":"git","url":"http://github.com/assaf/lazybird"},"bugs":{"url":"http://github.com/assaf/lazybird/issues"},"licenses":[{"type":"MIT","url":"https://github.com/assaf/lazybird/blob/master/LICENSE"}],"devDependencies":{"mocha":"^2.0.1"},"gitHead":"fe42cfb658ce81b50a9b7c4716a4e6df818caff2","_id":"lazybird@1.0.0","_shasum":"7eb216b0cf4a58aa8047675d81e0eb1ce85a73a4","_from":".","_npmVersion":"2.1.10","_nodeVersion":"0.10.33","_npmUser":{"name":"assaf","email":"assaf@labnotes.org"},"maintainers":[{"name":"assaf","email":"assaf@labnotes.org"}],"dist":{"shasum":"7eb216b0cf4a58aa8047675d81e0eb1ce85a73a4","size":3451,"noattachment":false,"key":"/lazybird/-/lazybird-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/lazybird/download/lazybird-1.0.0.tgz"},"directories":{},"publish_time":1417817323517,"_cnpm_publish_time":1417817323517,"_hasShrinkwrap":false}},"readme":"# lazybird\n\nLazy promises using Bluebird.\n\n\n## Why?\n\nLazybird allows you to create a promise that will only start resolving when you\nattach the first fulfilled or rejected handler.  It \"resolves lazily\".\n\nIf promises are future values, then lazy promises are future values calculated\non demand.  Mostly this is useful to delay calculations that may never happen at\nall.  You can create the promise, pass its reference around, but not bother to\nresolve it until the value or action is necessary.\n\n[Zombie](http://zombie.labnotes.org/) uses lazy promises for its event loop.\nThe promise only resolves when you ask it to.\n\nFor example:\n\n```\n// Click the \"Edit\" link, it will show delete link next to each item\nreturn browser\n  .clickLink('#edit-items')\n  .then(function() {\n    // Waiting for the promise to resolve, as there's some\n    // animation and setTimeout involved\n\n    // Now click the delete link on one of these items\n    return browser\n      .clickLink('#delete-item-45')\n      .then(function() {\n        // Waiting for the promise to resolve, as it needs to\n        // make AJAX request to the server, wait for response\n\n        // Click the \"Done\" link to hide the delete links\n        //\n        // This method returns a promise but we don't care\n        // for the promise to resolve\n        browser.clickLink('#edit-done');\n        \n      });\n  });\n\n```\n\n\n## How?\n\nJust like any standard promise library, use `Lazybird` to create a new promise\nobject and pass it the resolver callback.  The only difference is, that resolved\nfunction is not called until you ask the promise to resolve.\n\nSince `Lazybird` is based on `Bluebird`, you get access to all the same methods\nincluding `then`, `catch`, `finally`, `done`, `reflect`, `value`, etc).\n\n\n## Example\n\n```\nconst Lazybird = require('lazybird');\n\nconst lazy = new Lazybird(function(resolve) {\n  console.log('Resolving');\n  resolve();\n});\n\nconsole.log('Waiting ...');\nsetTimeout(function() {\n  console.log('5 seconds later ...');\n  lazy.then(function() {\n    console.log('Resolved');\n  });\n}, 5000);\n```\n\nYou will see:\n\n```\nWaiting ...\n5 seconds later ...\nResolving\nResolved\n```\n\n","_attachments":{},"homepage":"https://github.com/assaf/lazybird","bugs":{"url":"http://github.com/assaf/lazybird/issues"}}