Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

duration-estimator

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duration-estimator

Agnostic duration estimator for asynchronous tasks

latest
Source
npmnpm
Version
0.1.4
Version published
Maintainers
1
Created
Source

duration-estimator

test build version

Agnostic duration estimator for asynchronous tasks. Estimates remaining time using a moving average whose length is configurable.

Install

Using npm:

npm install duration-estimator --save

Using umd bundle from cdn:

<script src="https://unpkg.com/duration-estimator"></script>
<!-- Globally available as DurationEstimator !-->

Using esm bundle from cdn:

<script type="module">
  import { DurationEstimator } from 'https://cdn.skypack.dev/duration-estimator'
</script>

Usage

import { DurationEstimator } from 'duration-estimator'

function task (onProgess) {
  // Asynchronous task yielding progress in range 0-1
}

const estimator = new DurationEstimator()

task(progress => console.log(`${estimator.estimate(progress)}ms remaining`))

The estimator can be reused after calling reset():

estimator.reset() // ready to make estimations for a new task

By default, the estimator computes remaining time based on the last 10 samples it got. You can change that by setting the moving average length:

new DurationEstimator(20) // Takes the last 20 samples in account
new DurationEstimator(Infinity) // Takes all samples in account

FAQs

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