import { wrapWithAbort } from './operators/withabort' ; import { throwIfAborted } from '../aborterror' ; template TSource param { AsyncIterable < TSource > } source param { AbortSignal } signal returns { Promise < Set < TSource > > } export async function toSet < TSource > ( source , signal ? ) { throwIfAborted ( signal ) ; const set = new Set < TSource > ( ) ; for await ( const item of wrapWithAbort ( source , signal ) ) { set . add ( item ) ; } return set ; }