Skip to content
A simple class to instantiate infinite loops of async functions without memory leaks.
JavaScript
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib removes non-dev dependencies, bumps version up to 2.0.1 Jun 21, 2019
perf improves performance test with more metrics Jun 25, 2018
test adds tests for error handling Jul 3, 2018
.gitignore
.travis.yml adds node.js 12 to travis config file Jun 21, 2019
LICENSE.md removes non-dev dependencies, bumps version up to 2.0.1 Jun 21, 2019
LoopyLoop.js removes non-dev dependencies, bumps version up to 2.0.1 Jun 21, 2019
README.md drops support for node.js version < 8.0.0 Jun 21, 2019
jsconfig.json adds jsconfig.json for MS Visual Studio Code Jul 2, 2018
package-lock.json fixes outdated dependencies, bumps version up Aug 21, 2019
package.json fixes outdated dependencies, bumps version up Aug 21, 2019

README.md

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);
Argument Description
task An 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:

Event Description
started Emitted after the loop has started running.
stopped Emitted after the loop has stopped running.
error Emitted 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

Method Description
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

You can’t perform that action at this time.