use promise for rate limit

This commit is contained in:
Namrata Jha
2021-12-22 16:05:18 +00:00
committed by GitHub
parent 0739cce1e8
commit 9ff1e31776
2 changed files with 28 additions and 32 deletions
+10 -21
View File
@@ -43,35 +43,24 @@ query {
}
}`
export function getRateLimit(token: string): Observable<RateLimitResponse> {
return from(
graphql(token, ratelimitQuery, {
headers: {
Accept: 'application/vnd.github.package-deletes-preview+json'
}
}) as Promise<RateLimitResponse>
).pipe(
catchError(err => {
return throwError(
err.errors && err.errors.length > 0
? `${err.errors[0].message}`
: `unknown error`
)
})
)
export async function getRateLimit(token: string): Promise<RateLimitResponse> {
return graphql(token, ratelimitQuery, {
headers: {
Accept: 'application/vnd.github.package-deletes-preview+json'
}
}) as Promise<RateLimitResponse>
}
export function deletePackageVersion(
packageVersionId: string,
token: string
): Observable<boolean> {
getRateLimit(token).pipe(
tap(value =>
console.log(
`login: ${value.viewer.login}, rate limit: ${value.ratelimit.limit}, cost: ${value.ratelimit.cost}, remaining: ${value.ratelimit.remaining}`
)
getRateLimit(token).then(value =>
console.log(
`login: ${value.viewer.login}, rate limit: ${value.ratelimit.limit}, cost: ${value.ratelimit.cost}, remaining: ${value.ratelimit.remaining}`
)
)
if (deleted === 99) {
console.log(`reaching rate limit`)
delay(5000)