import { Paginator } from "@aws-sdk/types" ; import { ListInstancesCommand , ListInstancesCommandInput , ListInstancesCommandOutput , } from "../commands/ListInstancesCommand" ; import { ServiceDiscovery } from "../ServiceDiscovery" ; import { ServiceDiscoveryClient } from "../ServiceDiscoveryClient" ; import { ServiceDiscoveryPaginationConfiguration } from "./Interfaces" ; private const makePagedClientRequest = async ( client , input , ... args ) : Promise < ListInstancesCommandOutput > => { return await client . send ( new ListInstancesCommand ( input ) , ... args ) ; } ; private const makePagedRequest = async ( client , input , ... args ) : Promise < ListInstancesCommandOutput > => { return await client . listInstances ( input , ... args ) ; } ; export async function * paginateListInstances ( config , input , ... additionalArguments ) { let token = config . startingToken || undefined ; let hasNext = true ; let page ; while ( hasNext ) { input . NextToken = token ; input [ "MaxResults" ] = config . pageSize ; if ( config . client instanceof ServiceDiscovery ) { page = await makePagedRequest ( config . client , input , ... additionalArguments ) ; } else if ( config . client instanceof ServiceDiscoveryClient ) { page = await makePagedClientRequest ( config . client , input , ... additionalArguments ) ; } else { throw new Error ( "Invalid client, expected ServiceDiscovery | ServiceDiscoveryClient" ) ; } yield page ; token = page . NextToken ; hasNext = ! ! token ; } return undefined ; }