Skip to content

Commit

Permalink
api [nfc]: Tighten comments about streaming JSON-plus-UTF-8 decoder
Browse files Browse the repository at this point in the history
This is a bit off the main line of what a reader of this method will
mostly want to know about (as the method is mainly about semantics,
not performance optimization).  So keep the comments fairly short,
to avoid distracting the reader's focus from the rest of the method.
  • Loading branch information
gnprice committed Oct 2, 2024
1 parent a792a89 commit 061821c
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/api/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,9 @@ class ApiConnection {
final int httpStatus = response.statusCode;
Map<String, dynamic>? json;
try {
// Pass the response stream through the `jsonUtf8Decoder` transformer,
// allowing decoding to start as soon as the response stream emits data
// chunks.
// The stream-oriented `bind` method allows decoding to happen in chunks
// while the response is still being downloaded, improving latency.
final jsonStream = jsonUtf8Decoder.bind(response.stream);

// Actually start listening to the response byte stream and wait for
// decoding to finish.
json = await jsonStream.single as Map<String, dynamic>?;
} catch (e) {
// We'll throw something below, seeing `json` is null.
Expand Down

0 comments on commit 061821c

Please sign in to comment.