Skip to content

Commit

Permalink
add await setTimeout in test (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-ayf authored May 21, 2024
1 parent e38a747 commit a2ce9a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class SyrinxStream extends Readable {
});

this._ended = true;
setImmediate(() => this._read());
}

_read() {
Expand Down
14 changes: 8 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const zlib = require("node:zlib");
const fs = require("node:fs");
const { Readable } = require("node:stream");
const { pipeline } = require("node:stream/promises");
const { setTimeout } = require("node:timers/promises");
const crypto = require("node:crypto");
const { Syrinx, EncoderType } = require("../lib");
const tar = require("tar-fs");
Expand Down Expand Up @@ -39,12 +40,13 @@ async function fetchAndExtract(url, path) {
*/
async function synthesize(syrinx, inputText, option) {
const stream = syrinx.synthesize(inputText, option);
return new Promise((resolve, reject) => {
const bufs = [];
stream.on("data", (d) => bufs.push(d));
stream.on("error", (err) => reject(err));
stream.on("end", () => resolve(bufs));
});
/** @type {Buffer[]} */
const result = [];
for await (const item of stream) {
result.push(item);
await setTimeout(20);
}
return result;
}

/**
Expand Down

0 comments on commit a2ce9a5

Please sign in to comment.