import type { VoiceConnection , VoiceConnectionStatus } from '../VoiceConnection' ; import type { AudioPlayer , AudioPlayerStatus } from '../audio/AudioPlayer' ; import { abortAfter } from './abortAfter' ; import EventEmitter , { once } from 'node:events' ; param target param status param timeoutOrSignal export function entersState ( target , status , timeoutOrSignal ) ; param target param status param timeoutOrSignal export function entersState ( target , status , timeoutOrSignal ) ; param target param status param timeoutOrSignal export async function entersState < T extends VoiceConnection | AudioPlayer > ( target , status , timeoutOrSignal ) { if ( target . state . status !== status ) { const [ ac , signal ] = typeof timeoutOrSignal === 'number' ? abortAfter ( timeoutOrSignal ) : [ undefined , timeoutOrSignal ] ; try { await once ( target as EventEmitter , status , { signal } ) ; } finally { ac ?. abort ( ) ; } } return target ; }