Skip to content

Commit fb994fb

Browse files
committed
refactor: convert onResponse and related methods from async to synchronous execution
1 parent 0336598 commit fb994fb

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

handwritten/storage/src/resumable-upload.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ export class Upload extends Writable {
13451345
},
13461346
};
13471347
const res = await this.authClient.request(combinedReqOpts);
1348-
const successfulRequest = await this.onResponse(res);
1348+
const successfulRequest = this.onResponse(res);
13491349
this.removeListener('error', errorCallback);
13501350

13511351
return successfulRequest ? res : null;
@@ -1354,7 +1354,7 @@ export class Upload extends Writable {
13541354
/**
13551355
* @return {bool} is the request good?
13561356
*/
1357-
private async onResponse(resp: GaxiosResponse) {
1357+
private onResponse(resp: GaxiosResponse) {
13581358
if (
13591359
resp.status !== 200 &&
13601360
this.retryOptions.retryableErrorFn!({
@@ -1363,7 +1363,7 @@ export class Upload extends Writable {
13631363
name: resp.statusText,
13641364
})
13651365
) {
1366-
await this.attemptDelayedRetry(resp);
1366+
this.attemptDelayedRetry(resp);
13671367
return false;
13681368
}
13691369

handwritten/storage/test/resumable-upload.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,10 +2275,10 @@ describe('resumable-upload', () => {
22752275
describe('500s', () => {
22762276
const RESP = {status: 500, data: 'error message from server'};
22772277

2278-
it('should increase the retry count if less than limit', async () => {
2278+
it('should increase the retry count if less than limit', () => {
22792279
up.getRetryDelay = () => 1;
22802280
assert.strictEqual(up.numRetries, 0);
2281-
assert.strictEqual(await up.onResponse(RESP), false);
2281+
assert.strictEqual(up.onResponse(RESP), false);
22822282
assert.strictEqual(up.numRetries, 1);
22832283
});
22842284

@@ -2292,12 +2292,10 @@ describe('resumable-upload', () => {
22922292
done();
22932293
};
22942294

2295-
(async () => {
2296-
await up.onResponse(RESP);
2297-
await up.onResponse(RESP);
2298-
await up.onResponse(RESP);
2299-
await up.onResponse(RESP);
2300-
})().catch(done);
2295+
up.onResponse(RESP);
2296+
up.onResponse(RESP);
2297+
up.onResponse(RESP);
2298+
up.onResponse(RESP);
23012299
});
23022300

23032301
describe('exponential back off', () => {
@@ -2323,7 +2321,7 @@ describe('resumable-upload', () => {
23232321
assert(delay <= maxTime);
23242322

23252323
// make it keep retrying until the limit is reached
2326-
void up.onResponse(RESP);
2324+
up.onResponse(RESP);
23272325
};
23282326

23292327
up.on('error', (err: Error) => {
@@ -2335,7 +2333,7 @@ describe('resumable-upload', () => {
23352333
done();
23362334
});
23372335

2338-
void up.onResponse(RESP);
2336+
up.onResponse(RESP);
23392337
clock.runAll();
23402338
});
23412339
});
@@ -2350,22 +2348,22 @@ describe('resumable-upload', () => {
23502348
assert.strictEqual(resp, RESP);
23512349
done();
23522350
});
2353-
void up.onResponse(RESP);
2351+
up.onResponse(RESP);
23542352
});
23552353

2356-
it('should return true', async () => {
2354+
it('should return true', () => {
23572355
up.getRetryDelay = () => 1;
2358-
assert.strictEqual(await up.onResponse(RESP), true);
2356+
assert.strictEqual(up.onResponse(RESP), true);
23592357
});
23602358

2361-
it('should handle a custom status code when passed a retry function', async () => {
2359+
it('should handle a custom status code when passed a retry function', () => {
23622360
up.getRetryDelay = () => 1;
23632361
const RESP = {status: 1000};
23642362
const customHandlerFunction = (err: ApiError) => {
23652363
return err.code === 1000;
23662364
};
23672365
up.retryOptions.retryableErrorFn = customHandlerFunction;
2368-
assert.strictEqual(await up.onResponse(RESP), false);
2366+
assert.strictEqual(up.onResponse(RESP), false);
23692367
});
23702368
});
23712369
});

0 commit comments

Comments
 (0)