Skip to content

Commit 09e8286

Browse files
author
Marco Brack
committed
Add a synchronous example
It demonstrates calling tick() without setInterval or setTimeout like in the other examples. Testing this is important because in version 2.0.0 synchronous calls to tick() seem to prevent the bar from rendering, see issue #170.
1 parent 30d70d9 commit 09e8286

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

examples/iterative.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* A simple progressbar with synchronous calls to tick()
3+
* (i.e. no setTimeout/setInterval)
4+
*/
5+
6+
var ProgressBar = require('../');
7+
8+
var len = 10000000; // Adjust to your machine's speed
9+
var bar = new ProgressBar('[:bar]', len);
10+
11+
for (var i = 0; i <= len; i++) {
12+
bar.tick();
13+
}

lib/node-progress.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,11 @@ ProgressBar.prototype.tick = function(len, tokens){
9393
this.curr += len
9494

9595
// schedule render
96-
if (this.renderThrottle === 0) {
97-
this.render();
98-
} else if (!this.renderThrottleTimeout) {
99-
this.renderThrottleTimeout = setTimeout(this.render.bind(this), this.renderThrottle);
100-
}
96+
this.render();
10197

10298
// progress complete
10399
if (this.curr >= this.total) {
104-
if (this.renderThrottleTimeout) this.render();
100+
this.render();
105101
this.complete = true;
106102
this.terminate();
107103
this.callback(this);

0 commit comments

Comments
 (0)