Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including loopyloop with all npm packages installed. Try it out:

var loopyloop = require("loopyloop")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

loopyloop v2.0.2

A simple class to instantiate infinite loops of async functions without memory leaks

LoopyLoop

Build Status

A simple class to instantiate infinite loops of async functions without memory leaks.

Usage

const LoopyLoop = require('loopyloop');

const loop = new LoopyLoop(async () => {
  // something async here
})
  .on('started', () => {})
  .on('stopped', () => {})
  .on('error', (err) => {})
  .start();

API

Constructor

const loop = new LoopyLoop(task, opts);
ArgumentDescription
taskAn async or otherwise Promise-returning function to be executed continuously.
[opts]An optional object of loop options.
[opts.maxChained]The optional maximum number of chained executions within the same tick of the JavaScript event loop. Defaults to 10.

Events

The LoopyLoop class extends EventEmitter and its instances emit the following events:

EventDescription
startedEmitted after the loop has started running.
stoppedEmitted after the loop has stopped running.
errorEmitted when the Promise returned by task rejects. The rejection's error is provided as the first argument to this event.

In addition to emitting the error event, a LoopyLoop instance will stop running when its task rejects.

Methods

MethodDescription
loop.start([cb])Starts the loop. The optional cb callback is added as a one-time listener to the started event.
loop.stop([cb])Stops the loop. The optional cb callback is added as a one-time listener to the stopped event.

Compatibility

LoopyLoop works with both modern async functions and functions that explicitely return Promises. Compatible with all Node.js versions >= 8.0.0.

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free