Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Retry mechanism for Node.js and the browsers

branch: master
Readme.md

Build Status

obsessed

Retry mechanism for Node.js and the browser.

Synopsis

var obsessed = require('obsessed');

Sync:

Obsessed will run the following code up to 8 times. If an error is thrown, it will continue invoking the callback until the limit is hit.

obsessed(8, function() {
  // do something risky

  if (failed) {
    throw new Error('oops');
  }
});

obsessed('8 times', function() {
  // do work
  throw new Error('oops');
});

Async:

Running a risky async task is pretty simple.

Supply a task and invoke the callback when you are done. If an error occurred during the execution of the code, pass it as an argument to done and Obsessed will retry the operation.

You can delay the execution of the attempts by calling delay.

end will be triggered with the operation is done.

function fn(done) {
  // async calls
  done(new Error('failed'));
};

function end(err, param, ...) {
  console.log(err);
};

obsessed('3 times')
  .task(fn)
  .delay(200)
  .end(end)
  .run();

Installation

Node.js:

$ npm install obsessed

Browser:

Download obsessed.min.js and include it in the html:

<script src="obsessed.min.js"></script>

Tests

Node.js:

$ npm install
$ make test

Browser:

  • Download the repository
  • Open test/browser/index.html in your favourite browser

License

(The MIT License)

Copyright (c) 2012 Veselin Todorov hi@vesln.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.