MCPcopy Create free account
hub / github.com/npkgz/cli-progress / Example5

Function Example5

examples/example.js:125–168  ·  view source on GitHub ↗
(onComplete)

Source from the content-addressed store, hash-verified

123}
124
125function Example5(onComplete){
126 // EXAMPLE 5 ---------------------------------------------
127 console.log('\nExample 5 - Custom Payload');
128 // create new progress bar
129 const b1 = new _progress.Bar({
130 format: 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | Speed: {speed}'
131 });
132
133 // initialize the bar - defining payload token "speed" with the default value "N/A"
134 b1.start(200, 0, {
135 speed: "N/A"
136 });
137
138 // the bar value - will be linear incremented
139 let value = 0;
140
141 const speedData = [];
142
143 // 20ms update rate
144 let timer = setInterval(function(){
145 // increment value
146 value++;
147
148 // example speed data
149 speedData.push(Math.random()*2+5);
150 const currentSpeedData = speedData.splice(-10);
151
152 // update the bar value
153 b1.update(value, {
154 speed: (currentSpeedData.reduce(function(a, b) { return a + b; }, 0) / currentSpeedData.length).toFixed(2) + "mb/s"
155 });
156
157 // set limit
158 if (value >= b1.getTotal()){
159 // stop timer
160 clearInterval(timer);
161
162 b1.stop();
163
164 // run complete callback
165 onComplete.apply(this);
166 }
167 }, 20);
168}
169
170
171function Example6(onComplete){

Callers 1

example.jsFile · 0.70

Calls 5

logMethod · 0.80
getTotalMethod · 0.80
startMethod · 0.45
updateMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…