Skip to content

PR closed due to unresolved review loop #8021

New issue

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

Closed
wants to merge 7 commits into from
38 changes: 19 additions & 19 deletions apps/site/pages/en/learn/getting-started/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ async function main() {
const data = await response.json();
console.log(data);
// returns something like:
// [
// {
// userId: 1,
// id: 1,
// title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
// body: 'quia et suscipit\n' +
// 'suscipit recusandae consequuntur expedita et cum\n' +
// 'reprehenderit molestiae ut ut quas totam\n' +
// 'nostrum rerum est autem sunt rem eveniet architecto'
// }
// userId: 1,
// id: 1,
// title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
// body: 'quia et suscipit\n' +
// 'suscipit recusandae consequuntur expedita et cum\n' +
// 'reprehenderit molestiae ut ut quas totam\n' +
// 'nostrum rerum est autem sunt rem eveniet architecto'
// }
// ]
}

main().catch(console.error);
Expand Down Expand Up @@ -108,10 +110,11 @@ async function streamOllamaCompletion(prompt) {
}

let partial = '';

const decoder = new TextDecoder();

for await (const chunk of body) {
partial += decoder.decode(chunk, { stream: true });
// Note: decoder.decode() with { stream: true } may buffer incomplete UTF-8 chunks.
Comment on lines 116 to +117
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this relevant to the code snippet?

  1. comments go above the block

console.log(partial);
}

Expand All @@ -134,7 +137,6 @@ try {

```js
import { Writable } from 'stream';

import { stream } from 'undici';

async function fetchGitHubRepos() {
Expand All @@ -155,23 +157,21 @@ async function fetchGitHubRepos() {
return new Writable({
write(chunk, encoding, callback) {
buffer += chunk.toString();

callback();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added?

},
final(callback) {
try {
const json = JSON.parse(buffer);
console.log(
'Repository Names:',
json.map(repo => repo.name)
);
buffer = '';
} catch (error) {
console.error('Error parsing JSON:', error);
} finally {
console.log('Stream processing completed.');
callback();
}

callback();
},
final(callback) {
console.log('Stream processing completed.');
callback();
Comment on lines 169 to -174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this demo is to showcase the callback, let's not change it to a try final

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with aviv here - sometimes we choose to show code concepts in isolation even if a production app would have far more rigor

},
});
}
Expand All @@ -181,4 +181,4 @@ async function fetchGitHubRepos() {
}

fetchGitHubRepos().catch(console.error);
```
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```