Skip to content
Browse files

Switch to docco comments.

  • Loading branch information...
1 parent 8201a39 commit d9a05c69a1ecdf96d4e3f1ec5d41b810d34a68cb @MathieuTurcotte committed May 19, 2013
View
206 docs/backoff.html
@@ -0,0 +1,206 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+ <title>backoff.js</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
+ <link rel="stylesheet" media="all" href="docco.css" />
+</head>
+<body>
+ <div id="container">
+ <div id="background"></div>
+
+ <ul id="jump_to">
+ <li>
+ <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
+ <a class="small" href="javascript:void(0);">+</a>
+ <div id="jump_wrapper">
+ <div id="jump_page">
+
+
+ <a class="source" href="index.html">
+ index.js
+ </a>
+
+
+ <a class="source" href="backoff.html">
+ backoff.js
+ </a>
+
+
+ <a class="source" href="function_call.html">
+ function_call.js
+ </a>
+
+
+ <a class="source" href="exponential.html">
+ exponential.js
+ </a>
+
+
+ <a class="source" href="fibonacci.html">
+ fibonacci.js
+ </a>
+
+
+ <a class="source" href="strategy.html">
+ strategy.js
+ </a>
+
+ </div>
+ </li>
+ </ul>
+
+ <ul class="sections">
+
+ <li id="title">
+ <div class="annotation">
+ <h1>backoff.js</h1>
+ </div>
+ </li>
+
+
+
+ <li id="section-1">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-1">&#182;</a>
+ </div>
+ <pre><code> Copyright (c) 2012 Mathieu Turcotte
+ Licensed under the MIT license.</code></pre>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="keyword">var</span> events = require(<span class="string">'events'</span>);
+<span class="keyword">var</span> util = require(<span class="string">'util'</span>);</pre></div></div>
+
+ </li>
+
+
+ <li id="section-2">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-2">&#182;</a>
+ </div>
+ <p>A class to hold the state of a backoff operation. Accepts a backoff strategy
+to generate the backoff delays.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="function"><span class="keyword">function</span> <span class="title">Backoff</span><span class="params">(backoffStrategy)</span> {</span>
+ events.EventEmitter.call(<span class="keyword">this</span>);
+
+ <span class="keyword">this</span>.backoffStrategy_ = backoffStrategy;
+ <span class="keyword">this</span>.maxNumberOfRetry_ = -<span class="number">1</span>;
+ <span class="keyword">this</span>.backoffNumber_ = <span class="number">0</span>;
+ <span class="keyword">this</span>.backoffDelay_ = <span class="number">0</span>;
+ <span class="keyword">this</span>.timeoutID_ = -<span class="number">1</span>;
+
+ <span class="keyword">this</span>.handlers = {
+ backoff: <span class="keyword">this</span>.onBackoff_.bind(<span class="keyword">this</span>)
+ };
+}
+util.inherits(Backoff, events.EventEmitter);</pre></div></div>
+
+ </li>
+
+
+ <li id="section-3">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>Sets a limit, greater than 0, on the maximum number of backoffs. A &#39;fail&#39;
+event will be emitted when the limit is reached.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>Backoff.prototype.failAfter = <span class="keyword">function</span>(maxNumberOfRetry) {
+ <span class="keyword">if</span> (maxNumberOfRetry &lt; <span class="number">1</span>) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'Maximum number of retry must be greater than 0. '</span> +
+ <span class="string">'Actual: '</span> + maxNumberOfRetry);
+ }
+
+ <span class="keyword">this</span>.maxNumberOfRetry_ = maxNumberOfRetry;
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-4">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-4">&#182;</a>
+ </div>
+ <p>Starts a backoff operation. Accepts an optional parameter to let the
+listeners know why the backoff operation was started.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>Backoff.prototype.backoff = <span class="keyword">function</span>(err) {
+ <span class="keyword">if</span> (<span class="keyword">this</span>.timeoutID_ !== -<span class="number">1</span>) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'Backoff in progress.'</span>);
+ }
+
+ <span class="keyword">if</span> (<span class="keyword">this</span>.backoffNumber_ === <span class="keyword">this</span>.maxNumberOfRetry_) {
+ <span class="keyword">this</span>.emit(<span class="string">'fail'</span>, err);
+ <span class="keyword">this</span>.reset();
+ } <span class="keyword">else</span> {
+ <span class="keyword">this</span>.backoffDelay_ = <span class="keyword">this</span>.backoffStrategy_.next();
+ <span class="keyword">this</span>.timeoutID_ = setTimeout(<span class="keyword">this</span>.handlers.backoff, <span class="keyword">this</span>.backoffDelay_);
+ <span class="keyword">this</span>.emit(<span class="string">'backoff'</span>, <span class="keyword">this</span>.backoffNumber_, <span class="keyword">this</span>.backoffDelay_, err);
+ }
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-5">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-5">&#182;</a>
+ </div>
+ <p>Handles the backoff timeout completion.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>Backoff.prototype.onBackoff_ = <span class="keyword">function</span>() {
+ <span class="keyword">this</span>.timeoutID_ = -<span class="number">1</span>;
+ <span class="keyword">this</span>.emit(<span class="string">'ready'</span>, <span class="keyword">this</span>.backoffNumber_, <span class="keyword">this</span>.backoffDelay_);
+ <span class="keyword">this</span>.backoffNumber_++;
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-6">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-6">&#182;</a>
+ </div>
+ <p>Stops any backoff operation and resets the backoff delay to its inital value.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>Backoff.prototype.reset = <span class="keyword">function</span>() {
+ <span class="keyword">this</span>.backoffNumber_ = <span class="number">0</span>;
+ <span class="keyword">this</span>.backoffStrategy_.reset();
+ clearTimeout(<span class="keyword">this</span>.timeoutID_);
+ <span class="keyword">this</span>.timeoutID_ = -<span class="number">1</span>;
+};
+
+module.exports = Backoff;</pre></div></div>
+
+ </li>
+
+ </ul>
+ </div>
+</body>
+</html>
View
500 docs/docco.css
@@ -0,0 +1,500 @@
+/*--------------------- Typography ----------------------------*/
+
+@font-face {
+ font-family: 'aller-light';
+ src: url('public/fonts/aller-light.eot');
+ src: url('public/fonts/aller-light.eot?#iefix') format('embedded-opentype'),
+ url('public/fonts/aller-light.woff') format('woff'),
+ url('public/fonts/aller-light.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+
+@font-face {
+ font-family: 'aller-bold';
+ src: url('public/fonts/aller-bold.eot');
+ src: url('public/fonts/aller-bold.eot?#iefix') format('embedded-opentype'),
+ url('public/fonts/aller-bold.woff') format('woff'),
+ url('public/fonts/aller-bold.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+
+@font-face {
+ font-family: 'novecento-bold';
+ src: url('public/fonts/novecento-bold.eot');
+ src: url('public/fonts/novecento-bold.eot?#iefix') format('embedded-opentype'),
+ url('public/fonts/novecento-bold.woff') format('woff'),
+ url('public/fonts/novecento-bold.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+
+/*--------------------- Layout ----------------------------*/
+html { height: 100%; }
+body {
+ font-family: "aller-light";
+ font-size: 14px;
+ line-height: 18px;
+ color: #30404f;
+ margin: 0; padding: 0;
+ height:100%;
+}
+#container { min-height: 100%; }
+
+a {
+ color: #000;
+}
+
+b, strong {
+ font-weight: normal;
+ font-family: "aller-bold";
+}
+
+p, ul, ol {
+ margin: 15px 0 0px;
+}
+
+h1, h2, h3, h4, h5, h6 {
+ color: #112233;
+ line-height: 1em;
+ font-weight: normal;
+ font-family: "novecento-bold";
+ text-transform: uppercase;
+ margin: 30px 0 15px 0;
+}
+
+h1 {
+ margin-top: 40px;
+}
+
+hr {
+ border: 0;
+ background: 1px solid #ddd;
+ height: 1px;
+ margin: 20px 0;
+}
+
+pre, tt, code {
+ font-size: 12px; line-height: 16px;
+ font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
+ margin: 0; padding: 0;
+}
+ .annotation pre {
+ display: block;
+ margin: 0;
+ padding: 7px 10px;
+ background: #fcfcfc;
+ -moz-box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
+ -webkit-box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
+ box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
+ overflow-x: auto;
+ }
+ .annotation pre code {
+ border: 0;
+ padding: 0;
+ background: transparent;
+ }
+
+
+blockquote {
+ border-left: 5px solid #ccc;
+ margin: 0;
+ padding: 1px 0 1px 1em;
+}
+ .sections blockquote p {
+ font-family: Menlo, Consolas, Monaco, monospace;
+ font-size: 12px; line-height: 16px;
+ color: #999;
+ margin: 10px 0 0;
+ white-space: pre-wrap;
+ }
+
+ul.sections {
+ list-style: none;
+ padding:0 0 5px 0;;
+ margin:0;
+}
+
+/*
+ Force border-box so that % widths fit the parent
+ container without overlap because of margin/padding.
+
+ More Info : http://www.quirksmode.org/css/box.html
+*/
+ul.sections > li > div {
+ -moz-box-sizing: border-box; /* firefox */
+ -ms-box-sizing: border-box; /* ie */
+ -webkit-box-sizing: border-box; /* webkit */
+ -khtml-box-sizing: border-box; /* konqueror */
+ box-sizing: border-box; /* css3 */
+}
+
+
+/*---------------------- Jump Page -----------------------------*/
+#jump_to, #jump_page {
+ margin: 0;
+ background: white;
+ -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
+ -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
+ font: 16px Arial;
+ cursor: pointer;
+ text-align: right;
+ list-style: none;
+}
+
+#jump_to a {
+ text-decoration: none;
+}
+
+#jump_to a.large {
+ display: none;
+}
+#jump_to a.small {
+ font-size: 22px;
+ font-weight: bold;
+ color: #676767;
+}
+
+#jump_to, #jump_wrapper {
+ position: fixed;
+ right: 0; top: 0;
+ padding: 10px 15px;
+ margin:0;
+}
+
+#jump_wrapper {
+ display: none;
+ padding:0;
+}
+
+#jump_to:hover #jump_wrapper {
+ display: block;
+}
+
+#jump_page {
+ padding: 5px 0 3px;
+ margin: 0 0 25px 25px;
+}
+
+#jump_page .source {
+ display: block;
+ padding: 15px;
+ text-decoration: none;
+ border-top: 1px solid #eee;
+}
+
+#jump_page .source:hover {
+ background: #f5f5ff;
+}
+
+#jump_page .source:first-child {
+}
+
+/*---------------------- Low resolutions (> 320px) ---------------------*/
+@media only screen and (min-width: 320px) {
+ .pilwrap { display: none; }
+
+ ul.sections > li > div {
+ display: block;
+ padding:5px 10px 0 10px;
+ }
+
+ ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol {
+ padding-left: 30px;
+ }
+
+ ul.sections > li > div.content {
+ background: #f5f5ff;
+ overflow-x:auto;
+ -webkit-box-shadow: inset 0 0 5px #e5e5ee;
+ box-shadow: inset 0 0 5px #e5e5ee;
+ border: 1px solid #dedede;
+ margin:5px 10px 5px 10px;
+ padding-bottom: 5px;
+ }
+
+ ul.sections > li > div.annotation pre {
+ margin: 7px 0 7px;
+ padding-left: 15px;
+ }
+
+ ul.sections > li > div.annotation p tt, .annotation code {
+ background: #f8f8ff;
+ border: 1px solid #dedede;
+ font-size: 12px;
+ padding: 0 0.2em;
+ }
+}
+
+/*---------------------- (> 481px) ---------------------*/
+@media only screen and (min-width: 481px) {
+ #container {
+ position: relative;
+ }
+ body {
+ background-color: #F5F5FF;
+ font-size: 15px;
+ line-height: 21px;
+ }
+ pre, tt, code {
+ line-height: 18px;
+ }
+ p, ul, ol {
+ margin: 0 0 15px;
+ }
+
+
+ #jump_to {
+ padding: 5px 10px;
+ }
+ #jump_wrapper {
+ padding: 0;
+ }
+ #jump_to, #jump_page {
+ font: 10px Arial;
+ text-transform: uppercase;
+ }
+ #jump_page .source {
+ padding: 5px 10px;
+ }
+ #jump_to a.large {
+ display: inline-block;
+ }
+ #jump_to a.small {
+ display: none;
+ }
+
+
+
+ #background {
+ position: absolute;
+ top: 0; bottom: 0;
+ width: 350px;
+ background: #fff;
+ border-right: 1px solid #e5e5ee;
+ z-index: -1;
+ }
+
+ ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol {
+ padding-left: 40px;
+ }
+
+ ul.sections > li {
+ white-space: nowrap;
+ }
+
+ ul.sections > li > div {
+ display: inline-block;
+ }
+
+ ul.sections > li > div.annotation {
+ max-width: 350px;
+ min-width: 350px;
+ min-height: 5px;
+ padding: 13px;
+ overflow-x: hidden;
+ white-space: normal;
+ vertical-align: top;
+ text-align: left;
+ }
+ ul.sections > li > div.annotation pre {
+ margin: 15px 0 15px;
+ padding-left: 15px;
+ }
+
+ ul.sections > li > div.content {
+ padding: 13px;
+ vertical-align: top;
+ background: #f5f5ff;
+ border: none;
+ -webkit-box-shadow: none;
+ box-shadow: none;
+ }
+
+ .pilwrap {
+ position: relative;
+ display: inline;
+ }
+
+ .pilcrow {
+ font: 12px Arial;
+ text-decoration: none;
+ color: #454545;
+ position: absolute;
+ top: 3px; left: -20px;
+ padding: 1px 2px;
+ opacity: 0;
+ -webkit-transition: opacity 0.2s linear;
+ }
+ .for-h1 .pilcrow {
+ top: 47px;
+ }
+ .for-h2 .pilcrow, .for-h3 .pilcrow, .for-h4 .pilcrow {
+ top: 35px;
+ }
+
+ ul.sections > li > div.annotation:hover .pilcrow {
+ opacity: 1;
+ }
+}
+
+/*---------------------- (> 1025px) ---------------------*/
+@media only screen and (min-width: 1025px) {
+
+ body {
+ font-size: 16px;
+ line-height: 24px;
+ }
+
+ #background {
+ width: 525px;
+ }
+ ul.sections > li > div.annotation {
+ max-width: 525px;
+ min-width: 525px;
+ padding: 10px 25px 1px 50px;
+ }
+ ul.sections > li > div.content {
+ padding: 9px 15px 16px 25px;
+ }
+}
+
+/*---------------------- Syntax Highlighting -----------------------------*/
+
+td.linenos { background-color: #f0f0f0; padding-right: 10px; }
+span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
+/*
+
+github.com style (c) Vasily Polovnyov <vast@whiteants.net>
+
+*/
+
+pre code {
+ display: block; padding: 0.5em;
+ color: #000;
+ background: #f8f8ff
+}
+
+pre .comment,
+pre .template_comment,
+pre .diff .header,
+pre .javadoc {
+ color: #408080;
+ font-style: italic
+}
+
+pre .keyword,
+pre .assignment,
+pre .literal,
+pre .css .rule .keyword,
+pre .winutils,
+pre .javascript .title,
+pre .lisp .title,
+pre .subst {
+ color: #954121;
+ /*font-weight: bold*/
+}
+
+pre .number,
+pre .hexcolor {
+ color: #40a070
+}
+
+pre .string,
+pre .tag .value,
+pre .phpdoc,
+pre .tex .formula {
+ color: #219161;
+}
+
+pre .title,
+pre .id {
+ color: #19469D;
+}
+pre .params {
+ color: #00F;
+}
+
+pre .javascript .title,
+pre .lisp .title,
+pre .subst {
+ font-weight: normal
+}
+
+pre .class .title,
+pre .haskell .label,
+pre .tex .command {
+ color: #458;
+ font-weight: bold
+}
+
+pre .tag,
+pre .tag .title,
+pre .rules .property,
+pre .django .tag .keyword {
+ color: #000080;
+ font-weight: normal
+}
+
+pre .attribute,
+pre .variable,
+pre .instancevar,
+pre .lisp .body {
+ color: #008080
+}
+
+pre .regexp {
+ color: #B68
+}
+
+pre .class {
+ color: #458;
+ font-weight: bold
+}
+
+pre .symbol,
+pre .ruby .symbol .string,
+pre .ruby .symbol .keyword,
+pre .ruby .symbol .keymethods,
+pre .lisp .keyword,
+pre .tex .special,
+pre .input_number {
+ color: #990073
+}
+
+pre .builtin,
+pre .constructor,
+pre .built_in,
+pre .lisp .title {
+ color: #0086b3
+}
+
+pre .preprocessor,
+pre .pi,
+pre .doctype,
+pre .shebang,
+pre .cdata {
+ color: #999;
+ font-weight: bold
+}
+
+pre .deletion {
+ background: #fdd
+}
+
+pre .addition {
+ background: #dfd
+}
+
+pre .diff .change {
+ background: #0086b3
+}
+
+pre .chunk {
+ color: #aaa
+}
+
+pre .tex .formula {
+ opacity: 0.5;
+}
View
118 docs/exponential.html
@@ -0,0 +1,118 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+ <title>exponential.js</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
+ <link rel="stylesheet" media="all" href="docco.css" />
+</head>
+<body>
+ <div id="container">
+ <div id="background"></div>
+
+ <ul id="jump_to">
+ <li>
+ <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
+ <a class="small" href="javascript:void(0);">+</a>
+ <div id="jump_wrapper">
+ <div id="jump_page">
+
+
+ <a class="source" href="index.html">
+ index.js
+ </a>
+
+
+ <a class="source" href="backoff.html">
+ backoff.js
+ </a>
+
+
+ <a class="source" href="function_call.html">
+ function_call.js
+ </a>
+
+
+ <a class="source" href="exponential.html">
+ exponential.js
+ </a>
+
+
+ <a class="source" href="fibonacci.html">
+ fibonacci.js
+ </a>
+
+
+ <a class="source" href="strategy.html">
+ strategy.js
+ </a>
+
+ </div>
+ </li>
+ </ul>
+
+ <ul class="sections">
+
+ <li id="title">
+ <div class="annotation">
+ <h1>exponential.js</h1>
+ </div>
+ </li>
+
+
+
+ <li id="section-1">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-1">&#182;</a>
+ </div>
+ <pre><code> Copyright (c) 2012 Mathieu Turcotte
+ Licensed under the MIT license.</code></pre>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="keyword">var</span> util = require(<span class="string">'util'</span>);
+
+<span class="keyword">var</span> BackoffStrategy = require(<span class="string">'./strategy'</span>);</pre></div></div>
+
+ </li>
+
+
+ <li id="section-2">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-2">&#182;</a>
+ </div>
+ <p>Exponential backoff strategy.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="function"><span class="keyword">function</span> <span class="title">ExponentialBackoffStrategy</span><span class="params">(options)</span> {</span>
+ BackoffStrategy.call(<span class="keyword">this</span>, options);
+ <span class="keyword">this</span>.backoffDelay_ = <span class="number">0</span>;
+ <span class="keyword">this</span>.nextBackoffDelay_ = <span class="keyword">this</span>.getInitialDelay();
+}
+util.inherits(ExponentialBackoffStrategy, BackoffStrategy);
+
+ExponentialBackoffStrategy.prototype.next_ = <span class="keyword">function</span>() {
+ <span class="keyword">this</span>.backoffDelay_ = Math.min(<span class="keyword">this</span>.nextBackoffDelay_, <span class="keyword">this</span>.getMaxDelay());
+ <span class="keyword">this</span>.nextBackoffDelay_ = <span class="keyword">this</span>.backoffDelay_ * <span class="number">2</span>;
+ <span class="keyword">return</span> <span class="keyword">this</span>.backoffDelay_;
+};
+
+ExponentialBackoffStrategy.prototype.reset_ = <span class="keyword">function</span>() {
+ <span class="keyword">this</span>.backoffDelay_ = <span class="number">0</span>;
+ <span class="keyword">this</span>.nextBackoffDelay_ = <span class="keyword">this</span>.getInitialDelay();
+};
+
+module.exports = ExponentialBackoffStrategy;</pre></div></div>
+
+ </li>
+
+ </ul>
+ </div>
+</body>
+</html>
View
119 docs/fibonacci.html
@@ -0,0 +1,119 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+ <title>fibonacci.js</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
+ <link rel="stylesheet" media="all" href="docco.css" />
+</head>
+<body>
+ <div id="container">
+ <div id="background"></div>
+
+ <ul id="jump_to">
+ <li>
+ <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
+ <a class="small" href="javascript:void(0);">+</a>
+ <div id="jump_wrapper">
+ <div id="jump_page">
+
+
+ <a class="source" href="index.html">
+ index.js
+ </a>
+
+
+ <a class="source" href="backoff.html">
+ backoff.js
+ </a>
+
+
+ <a class="source" href="function_call.html">
+ function_call.js
+ </a>
+
+
+ <a class="source" href="exponential.html">
+ exponential.js
+ </a>
+
+
+ <a class="source" href="fibonacci.html">
+ fibonacci.js
+ </a>
+
+
+ <a class="source" href="strategy.html">
+ strategy.js
+ </a>
+
+ </div>
+ </li>
+ </ul>
+
+ <ul class="sections">
+
+ <li id="title">
+ <div class="annotation">
+ <h1>fibonacci.js</h1>
+ </div>
+ </li>
+
+
+
+ <li id="section-1">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-1">&#182;</a>
+ </div>
+ <pre><code> Copyright (c) 2012 Mathieu Turcotte
+ Licensed under the MIT license.</code></pre>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="keyword">var</span> util = require(<span class="string">'util'</span>);
+
+<span class="keyword">var</span> BackoffStrategy = require(<span class="string">'./strategy'</span>);</pre></div></div>
+
+ </li>
+
+
+ <li id="section-2">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-2">&#182;</a>
+ </div>
+ <p>Fibonacci backoff strategy.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="function"><span class="keyword">function</span> <span class="title">FibonacciBackoffStrategy</span><span class="params">(options)</span> {</span>
+ BackoffStrategy.call(<span class="keyword">this</span>, options);
+ <span class="keyword">this</span>.backoffDelay_ = <span class="number">0</span>;
+ <span class="keyword">this</span>.nextBackoffDelay_ = <span class="keyword">this</span>.getInitialDelay();
+}
+util.inherits(FibonacciBackoffStrategy, BackoffStrategy);
+
+FibonacciBackoffStrategy.prototype.next_ = <span class="keyword">function</span>() {
+ <span class="keyword">var</span> backoffDelay = Math.min(<span class="keyword">this</span>.nextBackoffDelay_, <span class="keyword">this</span>.getMaxDelay());
+ <span class="keyword">this</span>.nextBackoffDelay_ += <span class="keyword">this</span>.backoffDelay_;
+ <span class="keyword">this</span>.backoffDelay_ = backoffDelay;
+ <span class="keyword">return</span> backoffDelay;
+};
+
+FibonacciBackoffStrategy.prototype.reset_ = <span class="keyword">function</span>() {
+ <span class="keyword">this</span>.nextBackoffDelay_ = <span class="keyword">this</span>.getInitialDelay();
+ <span class="keyword">this</span>.backoffDelay_ = <span class="number">0</span>;
+};
+
+module.exports = FibonacciBackoffStrategy;</pre></div></div>
+
+ </li>
+
+ </ul>
+ </div>
+</body>
+</html>
View
502 docs/function_call.html
@@ -0,0 +1,502 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+ <title>function_call.js</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
+ <link rel="stylesheet" media="all" href="docco.css" />
+</head>
+<body>
+ <div id="container">
+ <div id="background"></div>
+
+ <ul id="jump_to">
+ <li>
+ <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
+ <a class="small" href="javascript:void(0);">+</a>
+ <div id="jump_wrapper">
+ <div id="jump_page">
+
+
+ <a class="source" href="index.html">
+ index.js
+ </a>
+
+
+ <a class="source" href="backoff.html">
+ backoff.js
+ </a>
+
+
+ <a class="source" href="function_call.html">
+ function_call.js
+ </a>
+
+
+ <a class="source" href="exponential.html">
+ exponential.js
+ </a>
+
+
+ <a class="source" href="fibonacci.html">
+ fibonacci.js
+ </a>
+
+
+ <a class="source" href="strategy.html">
+ strategy.js
+ </a>
+
+ </div>
+ </li>
+ </ul>
+
+ <ul class="sections">
+
+ <li id="title">
+ <div class="annotation">
+ <h1>function_call.js</h1>
+ </div>
+ </li>
+
+
+
+ <li id="section-1">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-1">&#182;</a>
+ </div>
+ <pre><code> Copyright (c) 2012 Mathieu Turcotte
+ Licensed under the MIT license.</code></pre>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="keyword">var</span> events = require(<span class="string">'events'</span>);
+<span class="keyword">var</span> util = require(<span class="string">'util'</span>);
+
+<span class="keyword">var</span> Backoff = require(<span class="string">'./backoff'</span>);
+<span class="keyword">var</span> FibonacciBackoffStrategy = require(<span class="string">'./strategy/fibonacci'</span>);</pre></div></div>
+
+ </li>
+
+
+ <li id="section-2">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-2">&#182;</a>
+ </div>
+ <p>Checks whether the given value is a function.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="function"><span class="keyword">function</span> <span class="title">isFunction</span><span class="params">(val)</span> {</span>
+ <span class="keyword">return</span> <span class="keyword">typeof</span> val == <span class="string">'function'</span>;
+}</pre></div></div>
+
+ </li>
+
+
+ <li id="section-3">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>Wraps a function to be called in a backoff loop.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="function"><span class="keyword">function</span> <span class="title">FunctionCall</span><span class="params">(fn, args, callback)</span> {</span>
+ events.EventEmitter.call(<span class="keyword">this</span>);
+
+ <span class="keyword">if</span> (!isFunction(fn)) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'fn should be a function.'</span> +
+ <span class="string">'Actual: '</span> + <span class="keyword">typeof</span> fn);
+ }
+
+ <span class="keyword">if</span> (!isFunction(callback)) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'callback should be a function.'</span> +
+ <span class="string">'Actual: '</span> + <span class="keyword">typeof</span> fn);
+ }
+
+ <span class="keyword">this</span>.function_ = fn;
+ <span class="keyword">this</span>.arguments_ = args;
+ <span class="keyword">this</span>.callback_ = callback;
+ <span class="keyword">this</span>.results_ = [];
+
+ <span class="keyword">this</span>.backoff_ = <span class="literal">null</span>;
+ <span class="keyword">this</span>.strategy_ = <span class="literal">null</span>;
+ <span class="keyword">this</span>.failAfter_ = -<span class="number">1</span>;
+
+ <span class="keyword">this</span>.state_ = FunctionCall.State_.PENDING;
+}
+util.inherits(FunctionCall, events.EventEmitter);</pre></div></div>
+
+ </li>
+
+
+ <li id="section-4">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-4">&#182;</a>
+ </div>
+ <p>States in which the call can be.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.State_ = {</pre></div></div>
+
+ </li>
+
+
+ <li id="section-5">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-5">&#182;</a>
+ </div>
+ <p>Call isn&#39;t started yet.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre> PENDING: <span class="number">0</span>,</pre></div></div>
+
+ </li>
+
+
+ <li id="section-6">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-6">&#182;</a>
+ </div>
+ <p>Call is in progress.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre> RUNNING: <span class="number">1</span>,</pre></div></div>
+
+ </li>
+
+
+ <li id="section-7">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-7">&#182;</a>
+ </div>
+ <p>Call completed successfully which means that either the wrapped function
+returned successfully or the maximal number of backoffs was reached.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre> COMPLETED: <span class="number">2</span>,</pre></div></div>
+
+ </li>
+
+
+ <li id="section-8">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-8">&#182;</a>
+ </div>
+ <p>The call was aborted.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre> ABORTED: <span class="number">3</span>
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-9">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-9">&#182;</a>
+ </div>
+ <p>Checks whether the call is pending.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.isPending = <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="keyword">this</span>.state_ == FunctionCall.State_.PENDING;
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-10">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-10">&#182;</a>
+ </div>
+ <p>Checks whether the call is in progress.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.isRunning = <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="keyword">this</span>.state_ == FunctionCall.State_.RUNNING;
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-11">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-11">&#182;</a>
+ </div>
+ <p>Checks whether the call is completed.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.isCompleted = <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="keyword">this</span>.state_ == FunctionCall.State_.COMPLETED;
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-12">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-12">&#182;</a>
+ </div>
+ <p>Checks whether the call is aborted.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.isAborted = <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="keyword">this</span>.state_ == FunctionCall.State_.ABORTED;
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-13">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-13">&#182;</a>
+ </div>
+ <p>Sets the backoff strategy to use. Can only be called before the call is
+started otherwise an exception will be thrown.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.setStrategy = <span class="keyword">function</span>(strategy) {
+ <span class="keyword">if</span> (!<span class="keyword">this</span>.isPending()) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'FunctionCall in progress.'</span>);
+ }
+ <span class="keyword">this</span>.strategy_ = strategy;
+ <span class="keyword">return</span> <span class="keyword">this</span>; <span class="comment">// Return this for chaining.</span>
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-14">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-14">&#182;</a>
+ </div>
+ <p>Returns all intermediary results returned by the wrapped function since
+the initial call.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.getResults = <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="keyword">this</span>.results_.concat();
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-15">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-15">&#182;</a>
+ </div>
+ <p>Sets the backoff limit.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.failAfter = <span class="keyword">function</span>(maxNumberOfRetry) {
+ <span class="keyword">if</span> (!<span class="keyword">this</span>.isPending()) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'FunctionCall in progress.'</span>);
+ }
+ <span class="keyword">this</span>.failAfter_ = maxNumberOfRetry;
+ <span class="keyword">return</span> <span class="keyword">this</span>; <span class="comment">// Return this for chaining.</span>
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-16">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-16">&#182;</a>
+ </div>
+ <p>Aborts the call.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.abort = <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (<span class="keyword">this</span>.isCompleted()) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'FunctionCall already completed.'</span>);
+ }
+
+ <span class="keyword">if</span> (<span class="keyword">this</span>.isRunning()) {
+ <span class="keyword">this</span>.backoff_.reset();
+ }
+
+ <span class="keyword">this</span>.state_ = FunctionCall.State_.ABORTED;
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-17">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-17">&#182;</a>
+ </div>
+ <p>Initiates the call to the wrapped function. Accepts an optional factory
+function used to create the backoff instance; used when testing.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.start = <span class="keyword">function</span>(backoffFactory) {
+ <span class="keyword">if</span> (<span class="keyword">this</span>.isAborted()) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'FunctionCall aborted.'</span>);
+ } <span class="keyword">else</span> <span class="keyword">if</span> (!<span class="keyword">this</span>.isPending()) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'FunctionCall already started.'</span>);
+ }
+
+ <span class="keyword">var</span> strategy = <span class="keyword">this</span>.strategy_ || <span class="keyword">new</span> FibonacciBackoffStrategy();
+
+ <span class="keyword">this</span>.backoff_ = backoffFactory ?
+ backoffFactory(strategy) :
+ <span class="keyword">new</span> Backoff(strategy);
+
+ <span class="keyword">this</span>.backoff_.on(<span class="string">'ready'</span>, <span class="keyword">this</span>.doCall_.bind(<span class="keyword">this</span>));
+ <span class="keyword">this</span>.backoff_.on(<span class="string">'fail'</span>, <span class="keyword">this</span>.doCallback_.bind(<span class="keyword">this</span>));
+ <span class="keyword">this</span>.backoff_.on(<span class="string">'backoff'</span>, <span class="keyword">this</span>.handleBackoff_.bind(<span class="keyword">this</span>));
+
+ <span class="keyword">if</span> (<span class="keyword">this</span>.failAfter_ &gt; <span class="number">0</span>) {
+ <span class="keyword">this</span>.backoff_.failAfter(<span class="keyword">this</span>.failAfter_);
+ }
+
+ <span class="keyword">this</span>.state_ = FunctionCall.State_.RUNNING;
+ <span class="keyword">this</span>.doCall_();
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-18">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-18">&#182;</a>
+ </div>
+ <p>Calls the wrapped function.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.doCall_ = <span class="keyword">function</span>() {
+ <span class="keyword">var</span> eventArgs = [<span class="string">'call'</span>].concat(<span class="keyword">this</span>.arguments_);
+ events.EventEmitter.prototype.emit.apply(<span class="keyword">this</span>, eventArgs);
+ <span class="keyword">var</span> callback = <span class="keyword">this</span>.handleFunctionCallback_.bind(<span class="keyword">this</span>);
+ <span class="keyword">this</span>.function_.apply(<span class="literal">null</span>, <span class="keyword">this</span>.arguments_.concat(callback));
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-19">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-19">&#182;</a>
+ </div>
+ <p>Calls the wrapped function&#39;s callback with the last result returned by the
+wrapped function.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.doCallback_ = <span class="keyword">function</span>() {
+ <span class="keyword">var</span> args = <span class="keyword">this</span>.results_[<span class="keyword">this</span>.results_.length - <span class="number">1</span>];
+ <span class="keyword">this</span>.callback_.apply(<span class="literal">null</span>, args);
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-20">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-20">&#182;</a>
+ </div>
+ <p>Handles wrapped function&#39;s completion. This method acts as a replacement
+for the original callback function.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.handleFunctionCallback_ = <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (<span class="keyword">this</span>.isAborted()) {
+ <span class="keyword">return</span>;
+ }
+
+ <span class="keyword">var</span> args = Array.prototype.slice.call(arguments);
+ <span class="keyword">this</span>.results_.push(args); <span class="comment">// Save callback arguments.</span>
+ events.EventEmitter.prototype.emit.apply(<span class="keyword">this</span>, [<span class="string">'callback'</span>].concat(args));
+
+ <span class="keyword">if</span> (args[<span class="number">0</span>]) {
+ <span class="keyword">this</span>.backoff_.backoff(args[<span class="number">0</span>]);
+ } <span class="keyword">else</span> {
+ <span class="keyword">this</span>.state_ = FunctionCall.State_.COMPLETED;
+ <span class="keyword">this</span>.doCallback_();
+ }
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-21">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-21">&#182;</a>
+ </div>
+ <p>Handles the backoff event by reemitting it.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>FunctionCall.prototype.handleBackoff_ = <span class="keyword">function</span>(number, delay, err) {
+ <span class="keyword">this</span>.emit(<span class="string">'backoff'</span>, number, delay, err);
+};
+
+module.exports = FunctionCall;</pre></div></div>
+
+ </li>
+
+ </ul>
+ </div>
+</body>
+</html>
View
0 doc/backoff_events.png → docs/img/backoff_events.png
File renamed without changes
View
0 doc/function_call_events.png → docs/img/function_call_events.png
File renamed without changes
View
0 doc/layers.png → docs/img/layers.png
File renamed without changes
View
146 docs/index.html
@@ -0,0 +1,146 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+ <title>index.js</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
+ <link rel="stylesheet" media="all" href="docco.css" />
+</head>
+<body>
+ <div id="container">
+ <div id="background"></div>
+
+ <ul id="jump_to">
+ <li>
+ <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
+ <a class="small" href="javascript:void(0);">+</a>
+ <div id="jump_wrapper">
+ <div id="jump_page">
+
+
+ <a class="source" href="index.html">
+ index.js
+ </a>
+
+
+ <a class="source" href="backoff.html">
+ backoff.js
+ </a>
+
+
+ <a class="source" href="function_call.html">
+ function_call.js
+ </a>
+
+
+ <a class="source" href="exponential.html">
+ exponential.js
+ </a>
+
+
+ <a class="source" href="fibonacci.html">
+ fibonacci.js
+ </a>
+
+
+ <a class="source" href="strategy.html">
+ strategy.js
+ </a>
+
+ </div>
+ </li>
+ </ul>
+
+ <ul class="sections">
+
+ <li id="title">
+ <div class="annotation">
+ <h1>index.js</h1>
+ </div>
+ </li>
+
+
+
+ <li id="section-1">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-1">&#182;</a>
+ </div>
+ <pre><code> Copyright (c) 2012 Mathieu Turcotte
+ Licensed under the MIT license.</code></pre>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="keyword">var</span> Backoff = require(<span class="string">'./lib/backoff'</span>);
+<span class="keyword">var</span> ExponentialBackoffStrategy = require(<span class="string">'./lib/strategy/exponential'</span>);
+<span class="keyword">var</span> FibonacciBackoffStrategy = require(<span class="string">'./lib/strategy/fibonacci'</span>);
+<span class="keyword">var</span> FunctionCall = require(<span class="string">'./lib/function_call.js'</span>);
+
+module.exports.Backoff = Backoff;
+module.exports.FunctionCall = FunctionCall;
+module.exports.FibonacciStrategy = FibonacciBackoffStrategy;
+module.exports.ExponentialStrategy = ExponentialBackoffStrategy;</pre></div></div>
+
+ </li>
+
+
+ <li id="section-2">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-2">&#182;</a>
+ </div>
+ <p>Constructs a Fibonacci backoff.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>module.exports.fibonacci = <span class="keyword">function</span>(options) {
+ <span class="keyword">return</span> <span class="keyword">new</span> Backoff(<span class="keyword">new</span> FibonacciBackoffStrategy(options));
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-3">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>Constructs an exponential backoff.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>module.exports.exponential = <span class="keyword">function</span>(options) {
+ <span class="keyword">return</span> <span class="keyword">new</span> Backoff(<span class="keyword">new</span> ExponentialBackoffStrategy(options));
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-4">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-4">&#182;</a>
+ </div>
+ <p>Constructs a FunctionCall for the given function and arguments.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>module.exports.call = <span class="keyword">function</span>(fn, vargs, callback) {
+ <span class="keyword">var</span> args = Array.prototype.slice.call(arguments);
+ fn = args[<span class="number">0</span>];
+ vargs = args.slice(<span class="number">1</span>, args.length - <span class="number">1</span>);
+ callback = args[args.length - <span class="number">1</span>];
+ <span class="keyword">return</span> <span class="keyword">new</span> FunctionCall(fn, vargs, callback);
+};</pre></div></div>
+
+ </li>
+
+ </ul>
+ </div>
+</body>
+</html>
View
BIN docs/public/fonts/aller-bold.eot
Binary file not shown.
View
BIN docs/public/fonts/aller-bold.ttf
Binary file not shown.
View
BIN docs/public/fonts/aller-bold.woff
Binary file not shown.
View
BIN docs/public/fonts/aller-light.eot
Binary file not shown.
View
BIN docs/public/fonts/aller-light.ttf
Binary file not shown.
View
BIN docs/public/fonts/aller-light.woff
Binary file not shown.
View
BIN docs/public/fonts/novecento-bold.eot
Binary file not shown.
View
BIN docs/public/fonts/novecento-bold.ttf
Binary file not shown.
View
BIN docs/public/fonts/novecento-bold.woff
Binary file not shown.
View
375 docs/public/stylesheets/normalize.css
@@ -0,0 +1,375 @@
+/*! normalize.css v2.0.1 | MIT License | git.io/normalize */
+
+/* ==========================================================================
+ HTML5 display definitions
+ ========================================================================== */
+
+/*
+ * Corrects `block` display not defined in IE 8/9.
+ */
+
+article,
+aside,
+details,
+figcaption,
+figure,
+footer,
+header,
+hgroup,
+nav,
+section,
+summary {
+ display: block;
+}
+
+/*
+ * Corrects `inline-block` display not defined in IE 8/9.
+ */
+
+audio,
+canvas,
+video {
+ display: inline-block;
+}
+
+/*
+ * Prevents modern browsers from displaying `audio` without controls.
+ * Remove excess height in iOS 5 devices.
+ */
+
+audio:not([controls]) {
+ display: none;
+ height: 0;
+}
+
+/*
+ * Addresses styling for `hidden` attribute not present in IE 8/9.
+ */
+
+[hidden] {
+ display: none;
+}
+
+/* ==========================================================================
+ Base
+ ========================================================================== */
+
+/*
+ * 1. Sets default font family to sans-serif.
+ * 2. Prevents iOS text size adjust after orientation change, without disabling
+ * user zoom.
+ */
+
+html {
+ font-family: sans-serif; /* 1 */
+ -webkit-text-size-adjust: 100%; /* 2 */
+ -ms-text-size-adjust: 100%; /* 2 */
+}
+
+/*
+ * Removes default margin.
+ */
+
+body {
+ margin: 0;
+}
+
+/* ==========================================================================
+ Links
+ ========================================================================== */
+
+/*
+ * Addresses `outline` inconsistency between Chrome and other browsers.
+ */
+
+a:focus {
+ outline: thin dotted;
+}
+
+/*
+ * Improves readability when focused and also mouse hovered in all browsers.
+ */
+
+a:active,
+a:hover {
+ outline: 0;
+}
+
+/* ==========================================================================
+ Typography
+ ========================================================================== */
+
+/*
+ * Addresses `h1` font sizes within `section` and `article` in Firefox 4+,
+ * Safari 5, and Chrome.
+ */
+
+h1 {
+ font-size: 2em;
+}
+
+/*
+ * Addresses styling not present in IE 8/9, Safari 5, and Chrome.
+ */
+
+abbr[title] {
+ border-bottom: 1px dotted;
+}
+
+/*
+ * Addresses style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
+ */
+
+b,
+strong {
+ font-weight: bold;
+}
+
+/*
+ * Addresses styling not present in Safari 5 and Chrome.
+ */
+
+dfn {
+ font-style: italic;
+}
+
+/*
+ * Addresses styling not present in IE 8/9.
+ */
+
+mark {
+ background: #ff0;
+ color: #000;
+}
+
+
+/*
+ * Corrects font family set oddly in Safari 5 and Chrome.
+ */
+
+code,
+kbd,
+pre,
+samp {
+ font-family: monospace, serif;
+ font-size: 1em;
+}
+
+/*
+ * Improves readability of pre-formatted text in all browsers.
+ */
+
+pre {
+ white-space: pre;
+ white-space: pre-wrap;
+ word-wrap: break-word;
+}
+
+/*
+ * Sets consistent quote types.
+ */
+
+q {
+ quotes: "\201C" "\201D" "\2018" "\2019";
+}
+
+/*
+ * Addresses inconsistent and variable font size in all browsers.
+ */
+
+small {
+ font-size: 80%;
+}
+
+/*
+ * Prevents `sub` and `sup` affecting `line-height` in all browsers.
+ */
+
+sub,
+sup {
+ font-size: 75%;
+ line-height: 0;
+ position: relative;
+ vertical-align: baseline;
+}
+
+sup {
+ top: -0.5em;
+}
+
+sub {
+ bottom: -0.25em;
+}
+
+/* ==========================================================================
+ Embedded content
+ ========================================================================== */
+
+/*
+ * Removes border when inside `a` element in IE 8/9.
+ */
+
+img {
+ border: 0;
+}
+
+/*
+ * Corrects overflow displayed oddly in IE 9.
+ */
+
+svg:not(:root) {
+ overflow: hidden;
+}
+
+/* ==========================================================================
+ Figures
+ ========================================================================== */
+
+/*
+ * Addresses margin not present in IE 8/9 and Safari 5.
+ */
+
+figure {
+ margin: 0;
+}
+
+/* ==========================================================================
+ Forms
+ ========================================================================== */
+
+/*
+ * Define consistent border, margin, and padding.
+ */
+
+fieldset {
+ border: 1px solid #c0c0c0;
+ margin: 0 2px;
+ padding: 0.35em 0.625em 0.75em;
+}
+
+/*
+ * 1. Corrects color not being inherited in IE 8/9.
+ * 2. Remove padding so people aren't caught out if they zero out fieldsets.
+ */
+
+legend {
+ border: 0; /* 1 */
+ padding: 0; /* 2 */
+}
+
+/*
+ * 1. Corrects font family not being inherited in all browsers.
+ * 2. Corrects font size not being inherited in all browsers.
+ * 3. Addresses margins set differently in Firefox 4+, Safari 5, and Chrome
+ */
+
+button,
+input,
+select,
+textarea {
+ font-family: inherit; /* 1 */
+ font-size: 100%; /* 2 */
+ margin: 0; /* 3 */
+}
+
+/*
+ * Addresses Firefox 4+ setting `line-height` on `input` using `!important` in
+ * the UA stylesheet.
+ */
+
+button,
+input {
+ line-height: normal;
+}
+
+/*
+ * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
+ * and `video` controls.
+ * 2. Corrects inability to style clickable `input` types in iOS.
+ * 3. Improves usability and consistency of cursor style between image-type
+ * `input` and others.
+ */
+
+button,
+html input[type="button"], /* 1 */
+input[type="reset"],
+input[type="submit"] {
+ -webkit-appearance: button; /* 2 */
+ cursor: pointer; /* 3 */
+}
+
+/*
+ * Re-set default cursor for disabled elements.
+ */
+
+button[disabled],
+input[disabled] {
+ cursor: default;
+}
+
+/*
+ * 1. Addresses box sizing set to `content-box` in IE 8/9.
+ * 2. Removes excess padding in IE 8/9.
+ */
+
+input[type="checkbox"],
+input[type="radio"] {
+ box-sizing: border-box; /* 1 */
+ padding: 0; /* 2 */
+}
+
+/*
+ * 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome.
+ * 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome
+ * (include `-moz` to future-proof).
+ */
+
+input[type="search"] {
+ -webkit-appearance: textfield; /* 1 */
+ -moz-box-sizing: content-box;
+ -webkit-box-sizing: content-box; /* 2 */
+ box-sizing: content-box;
+}
+
+/*
+ * Removes inner padding and search cancel button in Safari 5 and Chrome
+ * on OS X.
+ */
+
+input[type="search"]::-webkit-search-cancel-button,
+input[type="search"]::-webkit-search-decoration {
+ -webkit-appearance: none;
+}
+
+/*
+ * Removes inner padding and border in Firefox 4+.
+ */
+
+button::-moz-focus-inner,
+input::-moz-focus-inner {
+ border: 0;
+ padding: 0;
+}
+
+/*
+ * 1. Removes default vertical scrollbar in IE 8/9.
+ * 2. Improves readability and alignment in all browsers.
+ */
+
+textarea {
+ overflow: auto; /* 1 */
+ vertical-align: top; /* 2 */
+}
+
+/* ==========================================================================
+ Tables
+ ========================================================================== */
+
+/*
+ * Remove most spacing between table cells.
+ */
+
+table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
View
244 docs/strategy.html
@@ -0,0 +1,244 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+ <title>strategy.js</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
+ <link rel="stylesheet" media="all" href="docco.css" />
+</head>
+<body>
+ <div id="container">
+ <div id="background"></div>
+
+ <ul id="jump_to">
+ <li>
+ <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
+ <a class="small" href="javascript:void(0);">+</a>
+ <div id="jump_wrapper">
+ <div id="jump_page">
+
+
+ <a class="source" href="index.html">
+ index.js
+ </a>
+
+
+ <a class="source" href="backoff.html">
+ backoff.js
+ </a>
+
+
+ <a class="source" href="function_call.html">
+ function_call.js
+ </a>
+
+
+ <a class="source" href="exponential.html">
+ exponential.js
+ </a>
+
+
+ <a class="source" href="fibonacci.html">
+ fibonacci.js
+ </a>
+
+
+ <a class="source" href="strategy.html">
+ strategy.js
+ </a>
+
+ </div>
+ </li>
+ </ul>
+
+ <ul class="sections">
+
+ <li id="title">
+ <div class="annotation">
+ <h1>strategy.js</h1>
+ </div>
+ </li>
+
+
+
+ <li id="section-1">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-1">&#182;</a>
+ </div>
+ <pre><code> Copyright (c) 2012 Mathieu Turcotte
+ Licensed under the MIT license.</code></pre>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="keyword">var</span> events = require(<span class="string">'events'</span>);
+<span class="keyword">var</span> util = require(<span class="string">'util'</span>);
+
+<span class="function"><span class="keyword">function</span> <span class="title">isDef</span><span class="params">(value)</span> {</span>
+ <span class="keyword">return</span> value !== <span class="literal">undefined</span> &amp;&amp; value !== <span class="literal">null</span>;
+}</pre></div></div>
+
+ </li>
+
+
+ <li id="section-2">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-2">&#182;</a>
+ </div>
+ <p>Abstract class defining the skeleton for the backoff strategies. Accepts an
+object holding the options for the backoff strategy:</p>
+<ul>
+<li><code>randomisationFactor</code>: The randomisation factor which must be between 0
+ and 1 where 1 equates to a randomization factor of 100% and 0 to no
+ randomization.</li>
+<li><code>initialDelay</code>: The backoff initial delay in milliseconds.</li>
+<li><code>maxDelay</code>: The backoff maximal delay in milliseconds.</li>
+</ul>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="function"><span class="keyword">function</span> <span class="title">BackoffStrategy</span><span class="params">(options)</span> {</span>
+ options = options || {};
+
+ <span class="keyword">if</span> (isDef(options.initialDelay) &amp;&amp; options.initialDelay &lt; <span class="number">1</span>) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'The initial timeout must be greater than 0.'</span>);
+ } <span class="keyword">else</span> <span class="keyword">if</span> (isDef(options.maxDelay) &amp;&amp; options.maxDelay &lt; <span class="number">1</span>) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'The maximal timeout must be greater than 0.'</span>);
+ }
+
+ <span class="keyword">this</span>.initialDelay_ = options.initialDelay || <span class="number">100</span>;
+ <span class="keyword">this</span>.maxDelay_ = options.maxDelay || <span class="number">10000</span>;
+
+ <span class="keyword">if</span> (<span class="keyword">this</span>.maxDelay_ &lt;= <span class="keyword">this</span>.initialDelay_) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'The maximal backoff delay must be '</span> +
+ <span class="string">'greater than the initial backoff delay.'</span>);
+ }
+
+ <span class="keyword">if</span> (isDef(options.randomisationFactor) &amp;&amp;
+ (options.randomisationFactor &lt; <span class="number">0</span> || options.randomisationFactor &gt; <span class="number">1</span>)) {
+ <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'The randomisation factor must be between 0 and 1.'</span>);
+ }
+
+ <span class="keyword">this</span>.randomisationFactor_ = options.randomisationFactor || <span class="number">0</span>;
+}</pre></div></div>
+
+ </li>
+
+
+ <li id="section-3">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>Gets the maximal backoff delay.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>BackoffStrategy.prototype.getMaxDelay = <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="keyword">this</span>.maxDelay_;
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-4">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-4">&#182;</a>
+ </div>
+ <p>Gets the initial backoff delay.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'><pre>BackoffStrategy.prototype.getInitialDelay = <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="keyword">this</span>.initialDelay_;
+};</pre></div></div>
+
+ </li>
+
+
+ <li id="section-5">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-5">&#182;</a>
+ </div>
+ <p>Template method that computes and returns the next backoff delay in
+milliseconds.</p>
+
+ </div>
+
+ <div class="content"><div class='highlight'