delay-repeater
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -15,6 +15,15 @@ 'use strict'; | ||
times--; | ||
var ret = fn.apply(null); | ||
var ret = void 0; | ||
try { | ||
ret = fn.apply(null); | ||
} catch (e) { | ||
e.remaining = times + 1; | ||
return onComplete.call(null, e); | ||
} | ||
if (ret && ret.then) { | ||
ret.then(function (r) { | ||
setTimeout(execute, interval); | ||
}, function (e) { | ||
e.remaining = times + 1; | ||
return onComplete.call(null, e); | ||
}); | ||
@@ -21,0 +30,0 @@ } else { |
{ | ||
"name": "delay-repeater", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Run a function repeatly with a delay", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,6 @@ # Run your code repeatly with a delay | ||
```js | ||
//es6 module | ||
import repeat from 'delay-repeater'; | ||
//or CommonJS require style | ||
const repeat = require('delay-repeater').default; | ||
@@ -20,4 +23,7 @@ const fn = () => { | ||
//or | ||
const done = () => { | ||
//or with an error first callback | ||
const done = (e) => { | ||
if (e) { | ||
return console.log(e); | ||
} | ||
console.log('3 times execution finished'); | ||
@@ -24,0 +30,0 @@ } |
@@ -12,6 +12,15 @@ 'use strict'; | ||
times--; | ||
const ret = fn.apply(null); | ||
let ret; | ||
try { | ||
ret = fn.apply(null); | ||
} catch (e) { | ||
e.remaining = times + 1; | ||
return onComplete.call(null, e); | ||
} | ||
if (ret && ret.then) { | ||
ret.then(r => { | ||
setTimeout(execute, interval); | ||
}, e => { | ||
e.remaining = times + 1; | ||
return onComplete.call(null, e); | ||
}) | ||
@@ -18,0 +27,0 @@ } else { |
'use strict'; | ||
import { repeat } from '../index'; | ||
import repeat from '../index'; | ||
import * as sinon from 'sinon'; | ||
@@ -43,2 +43,26 @@ import { expect } from 'chai'; | ||
}); | ||
it('should call done when fn is a promise', (done) => { | ||
const fn = function () { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(function() { | ||
reject(new Error('oops')); | ||
}, 100); | ||
}); | ||
} | ||
repeat(fn, 1, 300, (e) => { | ||
expect(e).to.be.exist; | ||
expect(e.remaining).to.be.equal(1); | ||
done(); | ||
}); | ||
}); | ||
it('should call done when fn throws', (done) => { | ||
const fn = function () { | ||
throw new Error('oops'); | ||
} | ||
repeat(fn, 1, 300, (e) => { | ||
expect(e).to.be.exist; | ||
expect(e.remaining).to.be.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4909
135
36