import { IParallelEnumerable , ParallelGeneratorType } from "../../types" ; import { nextIterationAsync } from "./_nextIterationAsync" ; param source param predicate returns export const countAsync = async < TSource > ( source , predicate ) => { const data = nextIterationAsync ( source , predicate ) ; let countPromise ; switch ( data . type ) { case ParallelGeneratorType . ArrayOfPromises : countPromise = Promise . all ( data . generator ( ) ) ; break ; case ParallelGeneratorType . PromiseOfPromises : countPromise = Promise . all ( await data . generator ( ) ) ; break ; } let totalCount = 0 ; for ( const value of await countPromise ) { if ( value ) { totalCount ++ ; } } return totalCount ; } ;