0.1.4 • Published 4 years ago

duration-estimator v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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
0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago