Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit d929d48

Browse files
committed
Clean up promises
1 parent c9938ff commit d929d48

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/voice/VoiceRecorder.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,32 @@ export class VoiceRecorder {
133133
dbMax: this.recorderFreqNode.maxDecibels,
134134
});
135135
}, 1000 / FREQ_SAMPLE_RATE) as any as number; // XXX: Linter doesn't understand timer environment
136-
return this.recorder.start().then(() => this.recording = true);
136+
await this.recorder.start();
137+
this.recording = true;
137138
}
138139

139140
public async stop(): Promise<Uint8Array> {
140141
if (!this.recording) {
141142
throw new Error("No recording to stop");
142143
}
144+
143145
// Disconnect the source early to start shutting down resources
144146
this.recorderSource.disconnect();
145-
return this.recorder.stop()
146-
// close the context after the recorder so the recorder doesn't try to
147-
// connect anything to the context (this would generate a warning)
148-
.then(() => this.recorderContext.close())
149-
// Now stop all the media tracks so we can release them back to the user/OS
150-
.then(() => this.recorderStream.getTracks().forEach(t => t.stop()))
151-
// Finally do our post-processing and clean up
152-
.then(() => {
153-
clearInterval(this.freqTimerId);
154-
this.recording = false;
155-
return this.recorder.close();
156-
}).then(() => this.buffer);
147+
await this.recorder.stop();
148+
149+
// close the context after the recorder so the recorder doesn't try to
150+
// connect anything to the context (this would generate a warning)
151+
await this.recorderContext.close();
152+
153+
// Now stop all the media tracks so we can release them back to the user/OS
154+
this.recorderStream.getTracks().forEach(t => t.stop());
155+
156+
// Finally do our post-processing and clean up
157+
clearInterval(this.freqTimerId);
158+
this.recording = false;
159+
await this.recorder.close();
160+
161+
return this.buffer;
157162
}
158163

159164
public async upload(): Promise<string> {

0 commit comments

Comments
 (0)