Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@cookielab.io/progress

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cookielab.io/progress

## Overview This package allows you to track progress, running time, operations per second, calculate ETA and consumed memory. It can measure rate of operations in time or percents done and remaining if number of operations to be performed is known.

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
23
-25.81%
Maintainers
4
Weekly downloads
 
Created
Source

Progress

Overview

This package allows you to track progress, running time, operations per second, calculate ETA and consumed memory. It can measure rate of operations in time or percents done and remaining if number of operations to be performed is known.

Installation

$ npm install --save @cookielab.io/configuration

or

$ yarn add @cookielab.io/progress

Usage

To track progess, .tick() function is used. It takes number of operations performed as parameter. Default value is 1.

You have to specify how do you want to log progress. There are 2 options available:

  • on .tick() change via .enableOnTickLogging() function
  • specified time interval via .enableIntervalLogging() function

Tracking percents

import {ProgressLogger} from '@cookielab.io/progress';

const forceUsers: string[] = ['Darth Vader', 'Luke Skywalker', 'Obi-Wan Kenobi', 'Yoda', 'Qui-Gon Jin', 'Mace Windu'];

const logger = new ProgressLogger(forceUsers.length); // to enable tracking of percents, we have to set total amount performed actions

logger.enableOnTickLogging((message: string): void => console.log(message)); // enable logging of progress when tick changes and set logging function
logger.start(); // starts measuring

forceUsers.forEach((user: string): void => {
	// do something 
	logger.tick(); // mark operation for this element as ended and log status
})

logger.end(); // stops measuring

Tracking rate

import {ProgressLogger} from '@cookielab.io/progress';

const forceUsers: string[] = ['Darth Vader', 'Luke Skywalker', 'Obi-Wan Kenobi', 'Yoda', 'Qui-Gon Jin', 'Mace Windu'];

const logger = new ProgressLogger();

logger.enableIntervalLogging(500, (message: string): void => console.log(message)); // enable logging of progress every 500 ms and set logging function
logger.start(); // starts measuring

forceUsers.forEach((user: string): void => {
	// do something

	logger.tick(number); // save number of operations performed
})

logger.end(); // stops measuring

API

new ProgressLogger(total?: number)

Used to initialize logger. If total is supplied, class measures percents, remaining percents and ETA. If total is not supplied, class measures rate of operations per ms.

.start(): void

Used to initialize logger measuring. It is already started in the constructor. This can be useful for restarts or to keep the time precise as much as possible when doing more preparations before the process starts.

.stop(): void

Used to stop logger measuring and logging.

tick(count: number = 1): void

Used to track progress change. You can specify number of operations performed. If not, 1 is used.

.enableOnTickLogging(logFunction: (message: string) => void): void

Used to enable logging when .tick() method is called. Parameter logFunction specifies the function that is called each time a tick method is called.

.enableIntervalLogging(interval: number, logFunction: (message: string) => void): void

Used to enable logging in specified interval in ms. Parameter interval specifies the interval in which the logFunction should be called. Parameter logFunction specifies the function that is called every specified interval.

disableLogging(): void

Used to disable logging. It stops at the end of measuring by default. This can be used explicitly at any time.

FAQs

Package last updated on 17 Jun 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