{"_id":"ondone","_rev":"165830","name":"ondone","description":"Wait for one or more async functions to be done.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"mixu","email":"mixu@mixu.net"}],"time":{"modified":"2021-06-03T11:45:43.000Z","created":"2014-11-14T03:51:33.575Z","1.0.0":"2014-11-14T03:51:33.575Z"},"users":{},"author":{"name":"Mikito Takada","email":"mixu@mixu.net","url":"http://mixu.net/"},"repository":{"type":"git","url":"https://github.com/mixu/ondone.git"},"versions":{"1.0.0":{"name":"ondone","version":"1.0.0","description":"Wait for one or more async functions to be done.","main":"index.js","scripts":{"test":"mocha -R spec test.js"},"repository":{"type":"git","url":"https://github.com/mixu/ondone.git"},"keywords":["async","flow","parallel","callback","cancel"],"author":{"name":"Mikito Takada","email":"mixu@mixu.net","url":"http://mixu.net/"},"license":"BSD","bugs":{"url":"https://github.com/mixu/ondone/issues"},"homepage":"https://github.com/mixu/ondone","devDependencies":{"async":"^0.9.0"},"gitHead":"b1ac3d49fb80f6886f4db50c43c612318b23e164","_id":"ondone@1.0.0","_shasum":"fb208316d7ac2951bdcc696a7d864bf21af7a008","_from":".","_npmVersion":"2.1.5","_nodeVersion":"0.10.32","_npmUser":{"name":"mixu","email":"mixu@mixu.net"},"maintainers":[{"name":"mixu","email":"mixu@mixu.net"}],"dist":{"shasum":"fb208316d7ac2951bdcc696a7d864bf21af7a008","size":2726,"noattachment":false,"key":"/ondone/-/ondone-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/ondone/download/ondone-1.0.0.tgz"},"directories":{},"publish_time":1415937093575,"_cnpm_publish_time":1415937093575,"_hasShrinkwrap":false}},"readme":"# ondone\n\nWait for one or more async functions to be done.\n\n## Installation\n\n```js\nnpm install --save ondone\n```\n\n## API\n\n```js\nvar ondone = require('ondone');\ntasks = ondone(tasks, doneFn);\n```\n\n`ondone` accepts an array of `tasks` and a done function (`doneFn`). It returns an array of functions that can be passed to any async execution engine (like `miniq` or `async.js`). It adds the following functionality:\n\n- once all of the tasks have completed, the done function is called (with no error or result argument)\n- if any of the tasks returns an error:\n    - the done function is called with the error\n    - the other tasks passed in the same array will be cancelled (will become no-ops)\n- if the done function to any callback is called twice, an error is thrown\n\nIn short, this is \"waiting for tasks to complete\" portion of async execution without the actual task execution logic. It helps keep async runners smaller (ondone is ~1000 bytes unminified) while allowing them to support more flexible task batching.\n\nTasks are callbacks that have a signature such as:\n\n- `function(done) {}`\n- `function(arg1, done) {}`\n- `function(arg1, arg2, ..., done)`\n\nthat is, the last argument to each task must be a `done` function. The `done` function should accept an `err` (error) parameter as it's first argument, and may have additional arguments after the `err` argument, e.g.:\n\n- `function done(err) {}`\n- `function done(err, arg) {}`\n- `function done(err, arg1, arg2, ...) {}`\n\n## Example\n\nHere, I'm taking a set of tasks and dividing it into two sets of tasks. When each set of tasks completes, the done function for that set is called:\n\n```js\nvar completedFirst = false,\n    completedSecond = false;\nasync.waterfall(\n    ondone([\n      function(callback){ callback(null, 'one', 'two'); },\n      function(arg1, arg2, callback){ callback(null, arg1 + arg2 + 'three');}\n      ], function() { completedFirst = true; })\n    .concat(\n      ondone([\n        function(arg1, callback){ callback(null, arg1 + 'done'); }\n      ], function() { completedSecond = true; }))\n  , function (err, result) {\n  assert.equal(result, 'onetwothreedone');\n  assert.ok(completedFirst);\n  assert.ok(completedSecond);\n});\n```\n\n# Related\n\n- https://github.com/ifit/waitress\n- https://github.com/eldargab/asyncloop\n- https://github.com/stagas/waits\n- https://github.com/taoyuan/cancelify\n- https://github.com/socialradar/hold\n- https://github.com/adamhalasz/nextjs\n- https://github.com/KoryNunn/wait-for\n","_attachments":{},"homepage":"https://github.com/mixu/ondone","bugs":{"url":"https://github.com/mixu/ondone/issues"},"license":"BSD"}