Skip to content

Commit

Permalink
Fix timeout error in some cases (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
billyct and sindresorhus authored Dec 14, 2021
1 parent 1b716ee commit 75e0ec9
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,6 @@ class Aperture {
recorderOptions.videoCodec = codecMap.get(videoCodec);
}

this.recorder = execa(
BIN, [
'record',
'--process-id',
this.processId,
JSON.stringify(recorderOptions)
]
);

this.isFileReady = (async () => {
await this.waitForEvent('onFileReady');
return this.tmpPath;
})();

const timeout = setTimeout(() => {
// `.stopRecording()` was called already
if (this.recorder === undefined) {
Expand All @@ -136,15 +122,6 @@ class Aperture {
reject(error);
}, 5000);

this.recorder.catch(error => {
clearTimeout(timeout);
delete this.recorder;
reject(error);
});

this.recorder.stdout.setEncoding('utf8');
this.recorder.stdout.on('data', log);

(async () => {
try {
await this.waitForEvent('onStart');
Expand All @@ -154,6 +131,29 @@ class Aperture {
reject(error);
}
})();

this.isFileReady = (async () => {
await this.waitForEvent('onFileReady');
return this.tmpPath;
})();

this.recorder = execa(
BIN, [
'record',
'--process-id',
this.processId,
JSON.stringify(recorderOptions)
]
);

this.recorder.catch(error => {
clearTimeout(timeout);
delete this.recorder;
reject(error);
});

this.recorder.stdout.setEncoding('utf8');
this.recorder.stdout.on('data', log);
});
}

Expand Down

0 comments on commit 75e0ec9

Please sign in to comment.