{"jam":{"main":"src/trier.js"},"bugs":{"url":"https://github.com/philbooth/trier.js/issues"},"dist":{"shasum":"39056efd58f9f3acda813cef7f7e3e57568b1cfa","tarball":"https://registry.npmjs.org/trier/-/trier-0.3.2.tgz","integrity":"sha512-awAjEH4xgEjR3+7zhC7gN+I1d1DJKtsPJ3CkfI7Xxrx25nOSowJZNdI6aE4Y6Dv2hrSx1x4Kv58vpBaTfF61qw==","signatures":[{"sig":"MEQCIBXAz7DAuOVRUZfCy5gUcRIyrV7eha6qiyE7I05HdxRwAiASrWAdNqkc6h9NuJ6E5MRUFEcdqKjENAW6AA4rnWIQxw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"./src/trier","name":"trier","_from":".","ender":"noop","author":{"name":"Phil Booth","email":"pmbooth@gmail.com"},"readme":"# trier.js\n\n[![Build status][ci-image]][ci-status]\n\nBecause everyone loves a trier!\nConditional\nand repeated\nfunction invocation\nfor node\nand browser.\n\n## Say what?\n\nSometimes,\nyou want to defer\ncalling a function\nuntil a certain\npre-requisite condition is met.\nOther times,\nyou want to\ncall a function\nrepeatedly\nuntil some post-requisite condition\nis satisfied.\nOccasionally,\nyou might even want\nto do both\nfor the same function.\n\nTo save you writing\nexplicit conditions\nand loops\non each of those occasions,\ntrier.js implements\na predicate-based approach\nthat hides the cruft\nbehind a simple,\nfunctional interface.\n\nAdditionally,\nit allows you to easily specify\nretry intervals\nand limits,\nso that your code\ndoesn't hog the CPU.\nIt also supports\nexponential incrementation\nof retry intervals,\nwhich can be useful\nwhen handling\nindefinite error states\nsuch as network failure.\n\n## How can I install it?\n\nYou can install trier.js\nwith one of\nthe package managers:\n[NPM];\n[Jam];\n[Bower];\nor [Component].\nThe package name\nfor the first three\nis `trier`\nand for Component\nit's `philbooth/trier.js`:\n\n```\nnpm install trier\n\njam install trier\n\nbower install trier\n\ncomponent install philbooth/trier.js\n```\n\nAlternatively,\nyou can just clone\nthe git repository\nfrom GitHub:\n\n```\ngit clone git@github.com:philbooth/trier.js.git\n```\n\n## How do I use it in my code?\n\nIf you are running in\n[Node.js][node],\n[Browserify]\nor another CommonJS-style\nenvironment,\nyou can `require`\ntrier.js like so:\n\n```javascript\nvar trier = require('trier');\n```\n\nIt also the supports\nthe AMD-style format\npreferred by [Require.js][require]:\n\n```javascript\nrequire.config({\n    paths: {\n        trier: 'trier/src/trier'\n    }\n});\n\nrequire([ 'trier' ], function (trier) {\n});\n```\n\nIf you are\nincluding trier.js\nwith an HTML `<script>` tag,\nor neither of the above environments\nare detected,\ntrier.js will just export its interface globally\nas `trier`.\n\ntrier.js\nhas no dependencies\nand exports\na single public function,\n`attempt`,\nwhich enables you to\nconditionally\nand repeatedly\ncall functions\nwithout writing\nexplicit `if` statements\nor loops.\n\n`trier.attempt` takes one argument,\nan options object\nthat supports\nthe following properties:\n\n* `when`:\n  A callback function\n  used to test the pre-condition\n  for function invocation.\n  Until `when` returns true\n  (or a truthy value),\n  the `action` function\n  will not be called.\n  If undefined,\n  it defaults to a function\n  defined as\n  `function () { return true; }`.\n* `until`:\n  A callback function\n  used to test the post-condition\n  for terminating\n  function invocation.\n  After `until` returns true\n  (or a truthy value),\n  the `action` function\n  will no longer be called.\n  If undefined,\n  it defaults to a function\n  defined as\n  `function () { return true; }`.\n* `action`:\n  The invocation target.\n  A function\n  that will be called\n  according to the values\n  returned by\n  `when`\n  and `until`.\n  If undefined,\n  it defaults to a function\n  defined as\n  `function () {}`.\n  If your implementation\n  of `action`\n  expects any arguments,\n  it will be treated\n  as asynchronous\n  and passed\n  an additional function parameter,\n  `done`.\n  You must call `done`\n  when the action\n  is finished.\n* `fail`:\n  The error handler.\n  A function\n  that will be called\n  if `limit`\n  falsey values\n  are returned by\n  `when` or `until`.\n  If undefined,\n  it defaults to a function\n  defined as\n  `function () {}`.\n* `pass`:\n  Success handler.\n  A function\n  that will be called\n  after `until`\n  has returned\n  truthily.\n  If undefined,\n  it defaults to a function\n  defined as\n  `function () {}`.\n* `limit`:\n  Failure limit,\n  representing the number of times\n  that `when`\n  and `until`\n  may return a falsey value,\n  before the invocation\n  is deemed to have failed\n  and attempts\n  to call `action`\n  will cease.\n  A negative number\n  indicates that the attempt\n  should never fail,\n  instead continuing indefinitely\n  until `when`\n  and `until`\n  have returned\n  truthy values.\n  Defaults to -1.\n* `interval`:\n  A number\n  representing the\n  retry interval,\n  in milliseconds.\n  Use a negative number to indicate\n  that each subsequent retry\n  should wait for twice the interval\n  from the preceding iteration\n  (i.e. exponential incrementation).\n  The default value is\n  -1000,\n  signifying that\n  the initial retry interval\n  should be one second\n  and that each subsequent retry\n  should double\n  the previous interval.\n* `context`:\n  The context object\n  (i.e. `this`)\n  on which to invoke\n  the functions\n  `when`,\n  `until`,\n  `action`,\n  `fail` and\n  `pass`.\n  Defaults to\n  an empty object.\n* `args`:\n  The arguments array\n  that will be provided\n  to the functions\n  `when`,\n  `action`,\n  `fail` and\n  `pass`.\n  Defaults to\n  an empty array.\n\nExamples:\n```javascript\n// Attempt to insert a database record, waiting until a\n// connection is available before doing so. The retry\n// interval is 1 second on each occasion and the call\n// will fail after 10 attempts.\ntrier.attempt({\n    when: function () {\n        return db.isConnected;\n    },\n    action: function () {\n        db.insert(record);\n    },\n    fail: function () {\n        log.error('No database connection, terminating.');\n        process.exit(1);\n    },\n    interval: 1000,\n    limit: 10\n});\n\n// Attempt to send an email message, optionally retrying with\n// exponentially increasing intervals starting at 1 second.\n// Continue to make attempts until the call succeeds.\nvar sent = false\ntrier.attempt({\n    until: function () {\n        return sent;\n    },\n    action: function (done) {\n        smtp.send(email, function (error) {\n            if (!error) {\n                sent = true;\n            }\n            done();\n        });\n    },\n    interval: -1000,\n    limit: -1\n});\n```\n\n## How do I set up the build environment?\n\nThe build environment relies on\nNode.js,\nNPM,\n[JSHint],\n[CoffeeScript],\n[Mocha],\n[Chai],\n[spooks.js][spooks] and\n[UglifyJS].\nAssuming that you already have\nNode.js\nand NPM\ninstalled,\nyou just need to run\n`npm install`\nto set up all of the dependencies\nas listed in `package.json`.\n\nThe unit tests are in `test/trier.coffee`.\nYou can run them with the command `npm test`.\n\n## What license is trier.js released under?\n\n[MIT][license]\n\n[ci-image]: https://secure.travis-ci.org/philbooth/trier.js.png?branch=master\n[ci-status]: http://travis-ci.org/#!/philbooth/trier.js\n[npm]: https://npmjs.org/\n[jam]: http://jamjs.org/\n[component]: http://component.io/\n[bower]: http://bower.io/\n[node]: http://nodejs.org/\n[browserify]: http://browserify.org/\n[require]: http://requirejs.org/\n[jshint]: https://github.com/jshint/node-jshint\n[coffeescript]: http://coffeescript.org/\n[mocha]: http://visionmedia.github.com/mocha\n[chai]: http://chaijs.com/\n[spooks]: https://github.com/philbooth/spooks.js\n[uglifyjs]: https://github.com/mishoo/UglifyJS\n[license]: https://github.com/philbooth/trier.js/blob/master/COPYING\n\n","license":"MIT","scripts":{"lint":"./node_modules/.bin/jshint ./src/trier.js --config config/jshint.json","test":"./node_modules/.bin/mocha --ui tdd --reporter spec --compilers coffee:coffee-script --colors ./test/trier.coffee","minify":"./node_modules/.bin/uglifyjs ./src/trier.js --compress --mangle --output ./lib/trier.min.js"},"_npmUser":{"name":"philbooth","email":"pmbooth@gmail.com"},"keywords":["repeat","retry","predicate","conditional","invocation","ender"],"deprecated":"Alas, trier is dead. Rest in peace, trier. But worry not! A phoenix rises from the flames; perhaps you should look at `tryer` instead!","repository":{"url":"https://github.com/philbooth/trier.js","type":"git"},"_npmVersion":"1.3.8","description":"Because everyone loves a trier! Conditional and repeated task invocation for node and browser.","maintainers":[{"name":"philbooth","email":"pmbooth@gmail.com"}],"contributors":[{"name":"Phil Booth","email":"pmbooth@gmail.com"}],"readmeFilename":"README.md","devDependencies":{"chai":"1.7.x","mocha":"1.13.x","jshint":"2.1.x","spooks":"0.5.x","uglify-js":"2.4.x","coffee-script":"1.6.x"},"_id":"trier@0.3.2","version":"0.3.2"}