import { ErrorString , InvalidOperationException } from "../../shared" ; import { IAsyncEnumerable } from "../../types" ; import { BasicAsyncEnumerable } from "../BasicAsyncEnumerable" ; type FromAsyncFunc = { param promises throws returns < TSource > ( promises ) : IAsyncEnumerable < TSource > ; param asyncIterable returns < TSource > ( asyncIterable ) : IAsyncEnumerable < TSource > ; } ; export const fromAsync = < TSource > ( promisesOrIterable ) => { if ( Array . isArray ( promisesOrIterable ) ) { if ( promisesOrIterable . length === 0 ) { throw new InvalidOperationException ( ErrorString . NoElements ) ; } return new BasicAsyncEnumerable ( async function * ( ) { for await ( const value of promisesOrIterable ) { yield value ; } } ) ; } else { return new BasicAsyncEnumerable ( promisesOrIterable ) ; } } ;