Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstanceCollection usability issue (probably other collections too) #21

Open
dpittner opened this issue Dec 11, 2021 · 0 comments
Open

Comments

@dpittner
Copy link
Member

What: enumerate all vm instances in a situation where there are more than can be listed with a single request.

following the idiomatic paradigm of Javascript the SDK should ideally provide an async generator function that deals with pagination. At least there should be an easier way to paginate than to parse the response to assemble the next request. This is likely to affect all collections dealt with by the SDK (maybe a generic SDK generation thing)

Pagination is required in such a case, but the SDK is not helping in any way to iterate all pages, the following needs to be used and is pretty cumbersome: (ideally something like listInstances should be provided by the SDK for convenience)

async function *listInstances() {
	// get first page
	let response = await service.listInstances({ limit: 1 });
	do {
		for (let idx = 0; idx < response.result.instances.length; idx++) {
			yield response.result.instances[idx];
		}
		// get next page if there is one...this is the ugly part
		if (response.result.next) {
			const nextUrl = new URL(response.result.next.href);
			response = await service.listInstances({ limit: 1, start: nextUrl.searchParams.get("start") });
		} else {
			response = null;
		}
	} while (response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant