We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
i wont bother implementing this into the api, but think its a very usefull function, so thats why i wanna share it.
basicly an easy universal "wrapper" for pagination requests.
here you go :P
async function withPagination(func, args) { try { var result = await func(args); while (result.pagination.cursor) { const cursor = result.pagination.cursor; //console.log(`paginating ${cursor}`); const newargs = { ...args, after: cursor }; // new response with cursor const resp = await func(newargs); // replace cursor result.pagination.cursor = resp.pagination.cursor; // append data for (let dat of resp.data) { result.data.push(dat); } } return result; } catch (err) { console.error(err); } }
example usage:
async function getClips() { const users = await twitch.getUsers("someuser"); const user = users.data[0]; const broadcaster_id = user.id; const clips = await withPagination( async (args) => { return await twitch.getClips(args); }, { broadcaster_id } ); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
i wont bother implementing this into the api, but think its a very usefull function, so thats why i wanna share it.
basicly an easy universal "wrapper" for pagination requests.
here you go :P
example usage:
The text was updated successfully, but these errors were encountered: