Fakeprogress
Simulate smooth progression easily and combine real progression and fake progression.
Install
npm install fake-progress
Basic example
var FakeProgress = ; // Create the fake progress with a timeConstant of 10 seconds// it means that :// after 10 seconds, progress will be 0.6321 ( = 1-Math.exp(-1) )// after 20 seconds, progress will be 0.8646 ( = 1-Math.exp(-2) )// and so onevar p = timeConstant : 10000 autoStart : true; var { }; var { console;}; var interval = ; var { p; ; console}; ;
will print
Progress is 8.6 %
Progress is 17.3 %
Progress is 25.2 %
Progress is 32.3 %
...
The chart of progression over time.
Until the end is triggered, the progression is following the exponential curve, once "end" is triggered, progression goes to 100%.
More complex
In this example we will mix 3 functions, A and C are classical async functions, B is an async function with a 'real' callback.
Create 2 async function a, c
a and c are 2 basic async functions without progress.
const a = { ;}; const c = { ;};
Create a class for event emitter with linear progress
b will be an instance of an event emmiter that has a progress event
const B = { EventEmitter; let count = 0; const self = this; const totalCount = 30; self; self_intervalId = ;}; util;
Create a fake progress and log his value over time
const p = {}; const onEachDeciSecond = { console;}; ; const interval = ;
Create sub progress bar of p, for a progress
A has no progress so we fake his progress. A succeed in 1000 ms, so we can consider 500 ms is a good timeConstant.
const aProgress = p;
Call async chain
Each time on the async chain, subProgress.stop() then call createSubProgress() to create a new subProgress.
;
Call everything
After each call, stop previous sub, and create a new subProgress for next request.
;
All together
see source
Results
Documentation
See inside the code, documentated using JSDoc