{"_id":"nestableflow","_rev":"5-9c11cc3ff0162bcdb3e387a2ff1462d6","name":"nestableflow","description":"Nestable flow-control module.","dist-tags":{"latest":"0.0.14"},"versions":{"0.0.14":{"name":"nestableflow","author":{"name":"Daisuke MINO","email":"daisuke.mino@gmail.com"},"description":"Nestable flow-control module.","version":"0.0.14","main":"lib/flow","license":"MIT","scripts":{"test":"nodeunit test/test-flow.js"},"readme":"# flow.js\nAsynchronous flow-control (serial, parallel, repeat, wait, function) module for Node.js, RequireJS, and browser.\n\n## Installation (Node.js)\n\n    $ npm install nestableflow\n\n## Inspired\n* [東京Node学園#1「非同期プログラミングの改善」のエッセンス](http://www.slideshare.net/koichik/node1)\n* [BetweenAS3/en - Spark project](http://www.libspark.org/wiki/BetweenAS3/en)\n\n## Features\n* Nesting flow.\n* Group error handlers together in one handler.\n\n## Definition\n* **flow** - Instance of `Flow`. The block of process contains some flow or function.\n* **actor** - Instance of `Flow` or `Function`. The components making up a flow.\n\n## API Documentation\n\n### Class Methods\n* **serial(actor\\[, actor, ...\\])** - \\[static\\] Create serial flow with arguments of actor. (suger)\n* **serialActors(actors)** - \\[static\\] Create serial flow with array of actor.\n* **parallel(actor\\[, actor, ...\\])** - \\[static\\] Create parallel flow with arguments of actor. (suger)\n* **parallelActors(actors)** - \\[static\\] Create parallel flow with array of actor.\n* **repeat(actor, repeatCount)** - \\[static\\] Repeat actor.\n* **wait(delay)** - \\[static\\] Create an actor that contains timer.\n\n### Member Properties\n* **currentPhase** - Indicates the number of actor that is running now.\n* **totalPhase** - Indicates the total number of actors in the flow.\n\n### Member Methods\n* **start()** - Starts the flow, if it is not already running.\n* **next()** - Takes the flow into its next actor.\n* **stop()** - Stops the flow.\n* **reset()** - Stops the flow, if it is running, and sets the currentPhase property back to 0.\n\n### Event Handlers\n* **onError** - Calls when arguments of callback have some error object.\n* **onComplete** - Calls when the flow is finished.\n\n## Actor's method implement\n\n### Syncronous Actor\nJust call `flow.next()` on complete of the action.\n\n    function (flow, [argument, ...]) {\n      // do something\n      flow.next();\n    }\n\n### Asyncronous Actor\nSet callback `flow.next`.\n\n    function (next, [argument, ...]) {\n      fs.readFile('foo.txt', 'utf8', flow.next);\n    }\n\n## Phase Concept\n\n### Serial Flow\n\n    var root = Flow.serial(\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 0 3\n          flow.next();\n        }, 300);\n      },\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 1 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 1 3\n          flow.next();\n        }, 100);\n      },\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 2 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 2 3\n          flow.next();\n        }, 200);\n      }\n    );\n    root.onComplete = function () {\n      console.log(root.currentPhase, root.totalPhase);      // 3 3\n    };\n    root.start();\n\n### Parallel Flow\n\n    var root = Flow.parallel(\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 2 3\n          flow.next();\n        }, 300);\n      },\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 0 3\n          flow.next();\n        }, 100);\n      },\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 1 3\n          flow.next();\n        }, 200);\n      }\n    );\n    root.onComplete = function () {\n      console.log(root.currentPhase, root.totalPhase);      // 3 3\n    };\n    root.start();\n\n### Repeat Flow\n\n    var root = Flow.repeat(\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n                                                            // 1 3\n                                                            // 2 3\n        flow.next();\n      },\n      3\n    );\n    root.onComplete = function () {\n      console.log(root.currentPhase, root.totalPhase);      // 3 3\n    };\n    root.start();\n\n## Usage\n\n### File System: write -> read -> unlink\n\n[file.js](https://github.com/minodisk/flow.js/blob/master/example/file.js)\n\n    var fs = require('fs');\n    var Flow = require('nestableflow').Flow;\n    var now = (new Date()).toString();\n    var file = 'temp/file.txt';\n\n    // Callback style\n    fs.writeFile(file, now, function (err) {\n      if (err) {\n        console.log('error', err);\n        return;\n      }\n      fs.readFile(file, 'utf8', function (err, data) {\n        if (err) {\n          console.log('error', err);\n          return;\n        }\n        fs.unlink(file, function (err) {\n          if (err) {\n            console.log('error', err);\n            return;\n          }\n          console.log('complete');\n        });\n      });\n    });\n\n    // Flow style\n    var root = Flow.serial(\n      function (flow) {\n        fs.writeFile(file, now, flow.next);\n      },\n      function (flow) {\n        fs.readFile(file, 'utf8', flow.next);\n      },\n      function (flow, data) {\n        console.log(data);\n        fs.unlink(file, flow.next);\n      }\n    );\n    root.onError = function (err) {\n      console.log('error', err);\n    };\n    root.onComplete = function () {\n      console.log('complete');\n    };\n    root.start();\n\n### Mongoose: save -> find\n\n[mongoose.js](https://github.com/minodisk/flow-js/blob/master/example/mongoose.js)\n\n    var mongoose = require('mongoose');\n    var Flow = require('nestableflow').Flow;\n    var now = new Date();\n\n    mongoose.connect('mongodb://localhost/node_flow');\n    mongoose.model(\n      'Example',\n      new mongoose.Schema({\n        date: Date\n      })\n    );\n    var Example = mongoose.model('Example');\n\n    // Callback style\n    var example = new Example({\n      date: now\n    });\n    example.save(function (err) {\n      if (err) {\n        console.log('error', err);\n        return;\n      }\n      Example.find({}, [], function (err, examples) {\n        if (err) {\n          console.log('error', err);\n          return;\n        }\n        console.log(examples);\n        console.log('complete');\n      })\n    });\n\n    // Flow style\n    var root = Flow.serial(\n      function (flow) {\n        var example = new Example({\n          date: now\n        });\n        example.save(flow.next);\n      },\n      function (flow) {\n        Example.find({}, [], flow.next);\n      },\n      function (flow, examples) {\n        console.log(examples);\n        flow.next();\n      }\n    );\n    root.onError = function (err) {\n      console.log('error', err);\n    };\n    root.onComplete = function () {\n      console.log('complete');\n    };\n    root.start();\n\n### RequierJS\n\n[How to load flow.js with RequierJS](https://github.com/minodisk/flow-js/blob/master/example/require)\n\n    <script type=\"text/javascript\" src=\"require.js\"></script>\n    <script type=\"text/javascript\">\n      require(['../../lib/flow'], function (Flow) {\n        console.log(Flow);\n      });\n    </script>\n\n## License\n\nLicensed under the [MIT license](https://github.com/minodisk/flow-js/raw/master/LICENSE).\n","readmeFilename":"README.md","_id":"nestableflow@0.0.14","dist":{"shasum":"8bd204a3b13fa0e78db56533a5b40aeba02859bf","tarball":"https://registry.npmjs.org/nestableflow/-/nestableflow-0.0.14.tgz","integrity":"sha512-wCfdZaPXzcSw5Ig61uTksLLwAFREaPrAWwj2hZqpZTGbv0LdM6w5B1TwHrk21BM0H472RSP2WwCgAlzvAGe7zQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFYlvy56eSA9bTZ27uPAjpUMVmoxh5RHGJtpSB0V1MSgAiBPbvuSiw/HxNVESBW2Vf3bPWKCMCVDly41v4EnGRFZww=="}]},"_npmVersion":"1.1.65","_npmUser":{"name":"nherment","email":"nherment@gmail.com"},"maintainers":[{"name":"nherment","email":"nherment@gmail.com"}]}},"readme":"# flow.js\nAsynchronous flow-control (serial, parallel, repeat, wait, function) module for Node.js, RequireJS, and browser.\n\n## Installation (Node.js)\n\n    $ npm install nestableflow\n\n## Inspired\n* [東京Node学園#1「非同期プログラミングの改善」のエッセンス](http://www.slideshare.net/koichik/node1)\n* [BetweenAS3/en - Spark project](http://www.libspark.org/wiki/BetweenAS3/en)\n\n## Features\n* Nesting flow.\n* Group error handlers together in one handler.\n\n## Definition\n* **flow** - Instance of `Flow`. The block of process contains some flow or function.\n* **actor** - Instance of `Flow` or `Function`. The components making up a flow.\n\n## API Documentation\n\n### Class Methods\n* **serial(actor\\[, actor, ...\\])** - \\[static\\] Create serial flow with arguments of actor. (suger)\n* **serialActors(actors)** - \\[static\\] Create serial flow with array of actor.\n* **parallel(actor\\[, actor, ...\\])** - \\[static\\] Create parallel flow with arguments of actor. (suger)\n* **parallelActors(actors)** - \\[static\\] Create parallel flow with array of actor.\n* **repeat(actor, repeatCount)** - \\[static\\] Repeat actor.\n* **wait(delay)** - \\[static\\] Create an actor that contains timer.\n\n### Member Properties\n* **currentPhase** - Indicates the number of actor that is running now.\n* **totalPhase** - Indicates the total number of actors in the flow.\n\n### Member Methods\n* **start()** - Starts the flow, if it is not already running.\n* **next()** - Takes the flow into its next actor.\n* **stop()** - Stops the flow.\n* **reset()** - Stops the flow, if it is running, and sets the currentPhase property back to 0.\n\n### Event Handlers\n* **onError** - Calls when arguments of callback have some error object.\n* **onComplete** - Calls when the flow is finished.\n\n## Actor's method implement\n\n### Syncronous Actor\nJust call `flow.next()` on complete of the action.\n\n    function (flow, [argument, ...]) {\n      // do something\n      flow.next();\n    }\n\n### Asyncronous Actor\nSet callback `flow.next`.\n\n    function (next, [argument, ...]) {\n      fs.readFile('foo.txt', 'utf8', flow.next);\n    }\n\n## Phase Concept\n\n### Serial Flow\n\n    var root = Flow.serial(\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 0 3\n          flow.next();\n        }, 300);\n      },\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 1 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 1 3\n          flow.next();\n        }, 100);\n      },\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 2 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 2 3\n          flow.next();\n        }, 200);\n      }\n    );\n    root.onComplete = function () {\n      console.log(root.currentPhase, root.totalPhase);      // 3 3\n    };\n    root.start();\n\n### Parallel Flow\n\n    var root = Flow.parallel(\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 2 3\n          flow.next();\n        }, 300);\n      },\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 0 3\n          flow.next();\n        }, 100);\n      },\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n        setTimeout(function () {\n          console.log(flow.currentPhase, flow.totalPhase);  // 1 3\n          flow.next();\n        }, 200);\n      }\n    );\n    root.onComplete = function () {\n      console.log(root.currentPhase, root.totalPhase);      // 3 3\n    };\n    root.start();\n\n### Repeat Flow\n\n    var root = Flow.repeat(\n      function (flow) {\n        console.log(flow.currentPhase, flow.totalPhase);    // 0 3\n                                                            // 1 3\n                                                            // 2 3\n        flow.next();\n      },\n      3\n    );\n    root.onComplete = function () {\n      console.log(root.currentPhase, root.totalPhase);      // 3 3\n    };\n    root.start();\n\n## Usage\n\n### File System: write -> read -> unlink\n\n[file.js](https://github.com/minodisk/flow.js/blob/master/example/file.js)\n\n    var fs = require('fs');\n    var Flow = require('nestableflow').Flow;\n    var now = (new Date()).toString();\n    var file = 'temp/file.txt';\n\n    // Callback style\n    fs.writeFile(file, now, function (err) {\n      if (err) {\n        console.log('error', err);\n        return;\n      }\n      fs.readFile(file, 'utf8', function (err, data) {\n        if (err) {\n          console.log('error', err);\n          return;\n        }\n        fs.unlink(file, function (err) {\n          if (err) {\n            console.log('error', err);\n            return;\n          }\n          console.log('complete');\n        });\n      });\n    });\n\n    // Flow style\n    var root = Flow.serial(\n      function (flow) {\n        fs.writeFile(file, now, flow.next);\n      },\n      function (flow) {\n        fs.readFile(file, 'utf8', flow.next);\n      },\n      function (flow, data) {\n        console.log(data);\n        fs.unlink(file, flow.next);\n      }\n    );\n    root.onError = function (err) {\n      console.log('error', err);\n    };\n    root.onComplete = function () {\n      console.log('complete');\n    };\n    root.start();\n\n### Mongoose: save -> find\n\n[mongoose.js](https://github.com/minodisk/flow-js/blob/master/example/mongoose.js)\n\n    var mongoose = require('mongoose');\n    var Flow = require('nestableflow').Flow;\n    var now = new Date();\n\n    mongoose.connect('mongodb://localhost/node_flow');\n    mongoose.model(\n      'Example',\n      new mongoose.Schema({\n        date: Date\n      })\n    );\n    var Example = mongoose.model('Example');\n\n    // Callback style\n    var example = new Example({\n      date: now\n    });\n    example.save(function (err) {\n      if (err) {\n        console.log('error', err);\n        return;\n      }\n      Example.find({}, [], function (err, examples) {\n        if (err) {\n          console.log('error', err);\n          return;\n        }\n        console.log(examples);\n        console.log('complete');\n      })\n    });\n\n    // Flow style\n    var root = Flow.serial(\n      function (flow) {\n        var example = new Example({\n          date: now\n        });\n        example.save(flow.next);\n      },\n      function (flow) {\n        Example.find({}, [], flow.next);\n      },\n      function (flow, examples) {\n        console.log(examples);\n        flow.next();\n      }\n    );\n    root.onError = function (err) {\n      console.log('error', err);\n    };\n    root.onComplete = function () {\n      console.log('complete');\n    };\n    root.start();\n\n### RequierJS\n\n[How to load flow.js with RequierJS](https://github.com/minodisk/flow-js/blob/master/example/require)\n\n    <script type=\"text/javascript\" src=\"require.js\"></script>\n    <script type=\"text/javascript\">\n      require(['../../lib/flow'], function (Flow) {\n        console.log(Flow);\n      });\n    </script>\n\n## License\n\nLicensed under the [MIT license](https://github.com/minodisk/flow-js/raw/master/LICENSE).\n","maintainers":[{"name":"nherment","email":"nherment@gmail.com"}],"time":{"modified":"2022-06-21T00:35:31.931Z","created":"2012-12-03T15:28:24.561Z","0.0.14":"2012-12-03T15:28:25.570Z"},"author":{"name":"Daisuke MINO","email":"daisuke.mino@gmail.com"}}