New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

loopify

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loopify

Loop over a function

latest
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

loopify

Loop over a function

Usage

loopify = require("loopify");
var n = 0;
var action = function () {
	n++;
	console.log("Iteration " + n);
	if (n > 4) {
		// Throw null to stop looping without rejecting
		throw null;
	}
}
// Prints
// > Iteration 1
// > Iteration 2
// > Iteration 3
// > Iteration 4
// > Done!
loopify(action).then(function () {
	console.log("Done!");
});

// Add a sleep period of 50ms between callbacks
loopify(50, action).then(function () {
	console.log("Done!");
});

action = function () {
	n++;
	console.log("Iteration " + n);
	if (n > 4) {
		// Throw en error to reject the loopify promise.
		throw new Error("One loop too many.");
	}
}

// Prints
// > Iteration 1
// > Iteration 2
// > Iteration 3
// > Iteration 4
// > One loop too many.
loopify(action).catch(function (err) {
	console.error(err.message);
});



Keywords

loop

FAQs

Package last updated on 29 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts