-
-
Save varokas/e61ea4b15fad9002e28a29c13ff33a96 to your computer and use it in GitHub Desktop.
Revisions
-
briancavalier revised this gist
Feb 24, 2011 . 3 changed files with 33 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ function keepTrying(otherArgs, retryInterval, promise) { promise = promise||new Promise(); // try doing the important thing if(success) { promise.resolve(result); } else { setTimeout(function() { // Try again with incremental backoff, 2 can be // anything you want. You could even pass it in. // Cap max retry interval, which probably makes sense // in most cases. keepTrying(otherArgs, Math.min(maxRetryInterval, retryInterval * 2), promise); }, retryInterval); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ function tryAtMost(otherArgs, maxRetries, promise) { promise = promise||new Promise(); // try doing the important thing if(success) { promise.resolve(result); } else if (maxRetries > 0) { // Try again if we haven't reached maxRetries yet setTimeout(function() { tryAtMost(otherArgs, maxRetries - 1, promise); }, retryInterval); } else { promise.reject(error); } } -
briancavalier created this gist
Feb 24, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ function keepTrying(otherArgs, promise) { promise = promise||new Promise(); // try doing the important thing if(success) { promise.resolve(result); } else { setTimeout(function() { keepTrying(otherArgs, promise); }, retryInterval); } }