Skip to content

Commit

Permalink
Prevent fetch.pump recursively returning promises (grpc#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanb21 authored and MarcusLongmuir committed Apr 30, 2018
1 parent 311d3b0 commit fb9ccd3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ts/src/transports/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ class Fetch implements Transport {
this.options = transportOptions;
}

pump(readerArg: ReadableStreamReader, res: Response): Promise<void | Response> {
pump(readerArg: ReadableStreamReader, res: Response) {
this.reader = readerArg;
if (this.cancelled) {
// If the request was cancelled before the first pump then cancel it here
this.options.debug && debug("Fetch.pump.cancel at first pump");
return this.reader.cancel();
this.reader.cancel();
return;
}
return this.reader.read()
this.reader.read()
.then((result: { done: boolean, value: Uint8Array }) => {
if (result.done) {
detach(() => {
Expand All @@ -40,7 +41,8 @@ class Fetch implements Transport {
detach(() => {
this.options.onChunk(result.value);
});
return this.pump(this.reader, res);
this.pump(this.reader, res);
return;
});
}

Expand All @@ -56,7 +58,8 @@ class Fetch implements Transport {
this.options.onHeaders(new Metadata(res.headers as any), res.status);
});
if (res.body) {
return this.pump(res.body.getReader(), res)
this.pump(res.body.getReader(), res)
return;
}
return res;
}).catch(err => {
Expand Down

0 comments on commit fb9ccd3

Please sign in to comment.