Comparing version 0.15.0 to 0.15.1
var _ = require("./_"); | ||
var sleep = require("./sleep"); | ||
var $retryError = {}; | ||
module.exports = function (retries, fn, self) { | ||
module.exports = function (retries, span, fn, self) { | ||
var errs = [], args; | ||
if (_.isFunction(span)) { | ||
self = fn; | ||
fn = span; | ||
span = 0; | ||
} | ||
var countdown = _.isFunction(retries) ? | ||
retries : function () { return retries--; }; | ||
retries : function () { return sleep(span, retries--); }; | ||
@@ -9,0 +17,0 @@ function tryFn (isContinue) { |
@@ -280,2 +280,3 @@ // This file contains all the non-ES6-standard helpers based on promise. | ||
* @param {Number | Function} countdown How many times to retry before rejection. | ||
* @param {Number} span Optional. How long to wait before each retry in millisecond. | ||
* When it's a function `(errs) => Boolean | Promise.resolve(Boolean)`, | ||
@@ -289,3 +290,3 @@ * you can use it to create complex countdown logic, | ||
* @example | ||
* Retry 3 times before rejection. | ||
* Retry 3 times before rejection, wait 1 second before each retry. | ||
* ```js | ||
@@ -295,3 +296,3 @@ * var retry = require('yaku/lib/retry'); | ||
* | ||
* retry(3, request)('http://test.com').then( | ||
* retry(3, 1000, request)('http://test.com').then( | ||
* (body) => console.log(body), | ||
@@ -298,0 +299,0 @@ * (errs) => console.error(errs) |
/* | ||
Yaku v0.15.0 | ||
Yaku v0.15.1 | ||
(c) 2015 Yad Smood. http://ysmood.org | ||
@@ -4,0 +4,0 @@ License MIT |
{ | ||
"name": "yaku", | ||
"version": "0.15.0", | ||
"version": "0.15.1", | ||
"description": "A light-weight ES6 Promises/A+ implementation that doesn't hurt.", | ||
@@ -5,0 +5,0 @@ "main": "lib/yaku.js", |
@@ -12,3 +12,3 @@ <a href="http://promisesaplus.com/"> | ||
Yaku passed all the tests of [promises-aplus-tests][] and [promises-es6-tests][]. | ||
Yaku passed all the tests of [promises-aplus-tests][], [promises-es6-tests][], and even the [core-js tests][]. | ||
@@ -25,7 +25,7 @@ I am not an optimization freak, I try to keep the source code readable and maintainable. | ||
- The minified file is only 3.9KB (2KB gzipped) | ||
- [Better "possibly unhandled rejection" and "long stack trace"][docs/debugHelperComparison.md] than [Bluebird][] | ||
- The minified file is only 3.9KB (1.8KB gzipped) | ||
- Supports "uncaught rejection" and "long stack trace", [Comparison][docs/debugHelperComparison.md] | ||
- The only lib that passed all major Promise Spec tests, even the v8 native Promise doesn't | ||
- Designed to work on IE5+ and other major browsers | ||
- Much better performance than the native Promise | ||
- 100% compliant with Promises/A+ specs and nearly 100% compliant with ES6 specs | ||
- Designed to work on IE5+ and other major browsers | ||
- Well commented source code with every Promises/A+ spec | ||
@@ -112,6 +112,6 @@ | ||
- Will Yaku implement `done`, `finally`, `promisify`, etc? | ||
- Will Yaku implement `done`, `finally`, etc? | ||
> No. All non-ES6 APIs are only implemented for debugging and testing, which means when you remove Yaku, everything | ||
> should work well with ES6 native promise. If you need fancy and magic, go for [Bluebird][]. | ||
> should work well with ES6 native promise. | ||
@@ -123,10 +123,5 @@ - When using with Babel and Regenerator, the unhandled rejection doesn't work. | ||
- Better long stack trace support? | ||
> Latest Node.js and browsers are already support it. If you enabled it, Yaku will take advantage of it | ||
> without much overhead. Such as this library [longjohn][] for Node.js, or this article for [Chrome][crhome-lst]. | ||
- The name Yaku is weird? | ||
> The name `yaku` comes from the word `約束(yakusoku)` which means promise. | ||
> The name `yaku` comes from the word `約束(yaku soku)` which means promise. | ||
@@ -176,3 +171,3 @@ | ||
- [Observable](#observable) | ||
- [retry(countdown, fn, this)](#retrycountdown-fn-this) | ||
- [retry(countdown, span, fn, this)](#retrycountdown-span-fn-this) | ||
- [throw(err)](#throwerr) | ||
@@ -824,3 +819,3 @@ | ||
- ### **[retry(countdown, fn, this)](src/utils.js?source#L322)** | ||
- ### **[retry(countdown, span, fn, this)](src/utils.js?source#L323)** | ||
@@ -837,2 +832,6 @@ Retry a function until it resolves before a mount of times, or reject with all | ||
How many times to retry before rejection. | ||
- **<u>param</u>**: `span` { _Number_ } | ||
Optional. How long to wait before each retry in millisecond. | ||
When it's a function `(errs) => Boolean | Promise.resolve(Boolean)`, | ||
@@ -857,3 +856,3 @@ you can use it to create complex countdown logic, | ||
Retry 3 times before rejection. | ||
Retry 3 times before rejection, wait 1 second before each retry. | ||
```js | ||
@@ -863,3 +862,3 @@ var retry = require('yaku/lib/retry'); | ||
retry(3, request)('http://test.com').then( | ||
retry(3, 1000, request)('http://test.com').then( | ||
(body) => console.log(body), | ||
@@ -895,3 +894,3 @@ (errs) => console.error(errs) | ||
- ### **[throw(err)](src/utils.js?source#L336)** | ||
- ### **[throw(err)](src/utils.js?source#L337)** | ||
@@ -1113,2 +1112,3 @@ Throw an error to break the program. | ||
[ES6-promise]: https://github.com/jakearchibald/es6-promise | ||
[core-js tests]: https://github.com/ysmood/core-js/tree/promise-yaku | ||
[native]: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects | ||
@@ -1115,0 +1115,0 @@ [q]: https://github.com/kriskowal/q |
87165
1605