-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountdown.mjs
41 lines (37 loc) · 1.08 KB
/
countdown.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {tqdm} from 'node-console-progress-bar-tqdm';
import {default as example} from '../lib/definition.cjs';
import timers from 'node:timers/promises';
export default example({
title: 'Countdown',
description: 'Countdown, progress bar changes from full to empty',
tags: ['ESM', 'Iterator', 'countdown'],
file: import.meta.url,
async run() {
/**
* @implements Iterator
*/
class It {
static total = 100;
idx = 0;
next() {
const val = this.idx++;
if (val >= It.total) {
return {done: true, value: undefined};
}
return {done: false, value: val};
}
}
const opts = {
description: 'Countdown',
total: It.total,
initial: It.total,
step: -1,
};
const res = [];
for (const x of tqdm(new It(), opts)) {
res.push(x);
await timers.setTimeout(16);
}
console.log('Result length:', res.length);
},
});