discordjs / voice

Implementation of the Discord Voice API for discord.js and other JS/TS libraries
Apache License 2.0
328 stars 112 forks source link

feat(Util): support AbortSignal in entersState #171

Closed amishshah closed 2 years ago

amishshah commented 2 years ago

Please describe the changes this PR makes and why it should be merged:

Resolves #169

Allows users to pass in an AbortSignal to entersState if they'd like more control than just a timeout over cancelling the operation. Still allows for passing a delay as a number, but the minimum Node.js version has been upped to v16.

// Still backwards-compatible
await entersState(vc, VoiceConnectionStatus.Ready, 1000);

// New support for AbortSignals
// entersState will abort once 'someEvent' is emitted
const ac = new AbortController();
eventEmitter.once('someEvent', () => ac.abort());
await entersState(vc, VoiceConnectionStatus.Ready, ac.signal);

Status and versioning classification:

codecov[bot] commented 2 years ago

Codecov Report

Merging #171 (a693038) into main (dd5751b) will increase coverage by 1.26%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #171      +/-   ##
==========================================
+ Coverage   71.52%   72.78%   +1.26%     
==========================================
  Files          19       20       +1     
  Lines         906      904       -2     
  Branches      215      216       +1     
==========================================
+ Hits          648      658      +10     
+ Misses        256      244      -12     
  Partials        2        2              
Impacted Files Coverage Δ
src/util/abortAfter.ts 100.00% <100.00%> (ø)
src/util/entersState.ts 100.00% <100.00%> (+100.00%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update dd5751b...a693038. Read the comment docs.