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

patrolling

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

patrolling

Patrol buffers and flush periodically or when the buffer is full.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

patrolling

NPM Package Dependency status

NPM

Patrol buffers and flush, periodically or when the buffer is full.

Installation

npm install patrolling

Usage

import Patrolling from 'patrolling';

/**
 * @class Patrolling
 *
 * @constructor
 * @param {number} capacity The capacity of the buffer, i.e., maximum number of elements to hold.
 * @param {number} timeout Timeout in milliseconds to flush the buffer.
 * @param {function} flush How to flush the buffer.
 * @param {function} push How to push an element into the buffer.
 */
var patrolling = new Patrolling( capacity, timeout, flush, push );

Example

const buffer = [];

const capacity = 10;
const timeout = 100;
const flush = function() { buffer = []; console.log( 'flushed' ); }
const push = function( elem ) { buffer.push( elem ); }

const cache = new Patrolling( capacity, timeout, flush, push );

// At the tenth iteration the buffer is flushed because it hits the capacity.
// The buffer ends up with five elements left when the loop ends.
for ( var i = 0; i < 15; ++i ) {
  cache.push( i );
}

// If execution so far lasts for at least 100 milliseconds, the remaining five
// elements are flushed.

// You can flush it yourself anytime as well.
cache.flush();

License

MIT. See LICENSE.md for details.

Keywords

FAQs

Package last updated on 06 Sep 2020

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

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