sounder code (setTimeout is unreliable)

Massimo Melina committed Jan 20, 2022 at 18:02 UTC 43cee5328d91323899efdd856ba0a100018626b6
1 file changed +4 -5
src/QuickZipStream.ts
+4 -5
@@ -36,15 +36,14 @@ export class QuickZipStream extends Readable {
36
37 async calculateSize(howLong:number = 1000) {
38 this.prewalk = []
39 - let timeIsOut = false
40 - setTimeout(() => timeIsOut = true, howLong) // give it 1 second
41 - while (!timeIsOut) {
39 + const endBy = Date.now() + howLong
40 + while (1) {
41 + if (Date.now() >= endBy)
42 + return NaN
43 const { value } = await this.walker.next()
44 if (!value) break
45 this.prewalk.push(value) // we keep same shape of the generator, so
46 }
46 - if (timeIsOut)
47 - return NaN
47 let size = 0
48 let centralDirSize = 0
49 for (const file of this.prewalk) {