{"bugs":{"url":"https://github.com/FuturesJS/join/issues"},"dist":{"shasum":"cfb841db7b0a1dff132a07a582dbc06c21649713","tarball":"https://registry.npmjs.org/join/-/join-3.0.0.tgz","integrity":"sha512-RtCMVccL9rDfwqgQHpRx8ewxRDPkN2eoPbElrBJYMZIt0pTW2x8p2km4svpFmLb/sOPPRfD+ZwlJwYmONVVZzA==","signatures":[{"sig":"MEYCIQDD94CRDQMqH7c65qXRj0dsyHy9b1SpDehxbtxqxEq84AIhAJ++lkDRvLHpBJ3+373VNgmUmXkhkAh7uFAiimbi5sgj","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"join.js","name":"join","_from":"./","author":{"url":"http://coolaj86.com","name":"AJ ONeal","email":"coolaj86@gmail.com"},"readme":"Join\n===\n\nJoins any number of asynchronous calls together -\nsimilar to how `pthread_join` works for C threads\nand `when()` works for Q-style promises.\n\nIt's basically a callback counter that lets you know when everything is done.\n\nInstallation\n---\n\nNode.JS (Server):\n\n```bash\nnpm install join\n```\n\nBrowser:\n\nYou can install from bower:\n\n```bash\nbower install join\n```\n\nOr download the raw file from \n<https://raw.github.com/FuturesJS/join/master/join.js>:\n\n```bash\nwget https://raw.github.com/FuturesJS/join/master/join.js\n```\n\nBrowser Usage\n---\n\n```html\n<script src=\"join.js\"></script>\n```\n\n```javascript\n;(function () {\n  'use strict';\n\n  var join = window.Join.create()\n    ;\n\n  // Use `join.add()` in place of a callback function\n  setTimeout(join.add(), 500, 'I', 'really');\n  setTimeout(join.add(), 700, 'really', 'LOVE');\n  setTimeout(join.add(), 200, 'JavaScript');\n\n  // Use `join.notify()` for incremental updates\n  join.notify(function (i, args) {\n    console.log(\n      'Callback #' + (i + 1) \n    + ' of ' + join.length \n    + ' completed', args\n    );\n  });\n\n  // Use `join.then(cb)` to fire `cb` when all of the `join.add()` callbacks have been called.\n  join.then(function (i, love, js) {\n    console.log('All of the timeouts have completed');\n    console.log(i, love, js);\n  });\n}());\n\n```\n\nNode.js Usage\n---\n\n```javascript\n'use strict';\n\nvar request = require('request')\n  , Join = require('join').Join\n  , join = Join.create()\n  ;\n\n// Use `join.add()` in place of a callback function\nrequest.get('https://www.google.com', join.add());\nrequest.get('http://www.yahoo.com', join.add());\nrequest.get('https://www.bing.com', join.add());\n\n// Use `join.notify()` for incremental updates\njoin.notify(function (i, args) {\n  console.log(\n    'Callback #' + (i + 1) \n  + ' of ' + join.length \n  + ' completed', args\n  );\n});\n\n// Use `join.then(cb)` to fire `cb` when all of the `join.add()` callbacks have been called.\njoin.then(function (googleArgs, yahooArgs, bingArgs) {\n  console.log('All of the requests have completed');\n  console.log(googleArgs[2]);\n  console.log(yahooArgs[2]);\n  console.log(bingArgs[2]);\n});\n```\n\nAPI\n---\n\nJoin\n\n  * `join = Join.create(defaultContext=null)` - create a Join that will count callbacks\n  * `join.add()` - creates a joinable callback that you can throw around\n  * `join.notify(progressCallback, context=null)`\n  * `join.then(finalCallback, context=null)`\n    * Fires `finalCallback` when all joined callbacks have completed\n    * Must be called after the last `add()`\n  * `join.length` - the number of times `join.add()` has been called\n\nPotential Gotchas\n---\n\n### Order matters\n\nThe arguments to `join.then(cb)` are in the order that the `join.add()` were called.\n\n```javascript\n  callbackA = join.add();\n  callbackB = join.add();\n\n  doAsyncStuff(callbackB);\n  doAsyncStuff(callbackA);\n\n  join.then(function (callbackAArgs, callbackBArgs) {\n    console.log(callbackAArgs, callbackBArgs);\n  });\n```\n\n### Callback within a callback\n\nIf you handle the join callback inside of another callback\nthen you'll need to place the join callback in the parent scope.\n\nFails:\n```javascript\n  request.get('http://www.yahoo.com', join.add());\n  setTimeout(function () {\n    request.get('https://www.bing.com', join.add());\n  }, 100);\n\n  join.then(function () {\n    console.log('all completed');\n  });\n```\n\n\nWorks as expected:\n```javascript\n  request.get('http://www.yahoo.com', join.add());\n  bingCallback = join.add()\n  setTimeout(function () {\n    request.get('https://www.bing.com', bingCallback);\n  }, 100);\n```\n\n### Losing `this`ness\n\nFails:\n```javascript\n  // `doStuff` loses the `this` binding to `myObject`\n  join.then(myObject.doStuff);\n```\n\nWorks as expected:\n```\n  // `doStuff` retains the `this` binding\n  join.then(myObject.doStuff, myObject);\n```\n\nAlso works as expected:\n```\n  // `doStuff` retains the `this` binding\n  join.then(function (argsA, argsB, argsC) {\n    myObject.doStuff(argsA, argsB, argsC);\n  });\n```\n","engines":{"node":"*","ender":">= 0.5.0"},"_npmUser":{"name":"coolaj86","email":"coolaj86@gmail.com"},"homepage":"https://github.com/FuturesJS/join","keywords":["futuresjs","flow-control","async","asynchronous","futures","promises","deferreds","join","synchronize","util","browser"],"repository":{"url":"git://github.com/FuturesJS/join.git","type":"git"},"_npmVersion":"1.3.11","description":"The join / synchronize module of FuturesJS (Browser, Node.js, Bower, and Pakmanager)","directories":{"lib":"."},"maintainers":[{"name":"coolaj86","email":"coolaj86@gmail.com"}],"dependencies":{},"readmeFilename":"README.md","devDependencies":{},"optionalDependencies":{},"_id":"join@3.0.0","version":"3.0.0"}