import { wrapWithAbort } from './operators/withabort' ; import { throwIfAborted } from '../aborterror' ; template T param { AsyncIterable < T > } source param { number } index param { AbortSignal } signal returns { ( Promise < T | undefined > ) } export async function elementAt < T > ( source , index , signal ? ) { throwIfAborted ( signal ) ; let i = index ; for await ( const item of wrapWithAbort ( source , signal ) ) { if ( i === 0 ) { return item ; } i -- ; } return undefined ; }