Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

delay-repeater

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

delay-repeater - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

11

lib/repeater.js

@@ -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 {

2

package.json
{
"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();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc