Skip to content
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

Change asynchronous get to fetch suggestion. #83

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

haIIux
Copy link

@haIIux haIIux commented Dec 14, 2022

In the example displayed currently in the notes, it suggests that the asynchronous function would return instantaneously when it could return errors or throw. In my opinion, it would be better to recommend a namespace in which would reflect that accordingly.

The current example:

You can use get when performing asynchronous operations as well:

async function getUser(id) {
  const user = await fetch(`/api/user/${id}`)
  return user
}

The proposed change:

fetch

You can use fetch when performing asynchronous operations as well:

async function fetchUser(id) {
  const user = await fetch(`/api/user/${id}`)
  return user
}

The ideaology behind my suggestion is as follows. When you're playing fetch with a dog, the dog does not always immediately return. The dog may get distracted or while returning drop it before returning to the handler, thus erroring out and dropping the return.

@haIIux haIIux changed the title Change asynchronous to fetch suggestion. Change asynchronous get to fetch suggestion. Dec 14, 2022
You can use `get` when performing asynchronous operations as well:
### `fetch`

You can use `fetch` when performing asynchronous operations as well:
Copy link

Choose a reason for hiding this comment

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

I don't think that "as well" is appropriate here since it isn't connected with get anymore.

@haIIux haIIux requested a review from cjbarth November 14, 2023 15:43
@cjbarth
Copy link

cjbarth commented Nov 15, 2023

Why did you request my review since my previous comment is still open and unaddressed?

@haIIux
Copy link
Author

haIIux commented Nov 15, 2023

Why did you request my review since my previous comment is still open and unaddressed?

Appears actually to be an error with GitHub mobile. I had requested a review on a private repository.

I'll address your requested changes asap! I apologize for the inconvenience.

@letstri
Copy link

letstri commented Feb 16, 2024

I thing fetch should be in another cases.

get for returning value

const getUser = () => {
  return fetch('/user').then(res => res.json());
};

const user = await getUser();

console.log(user);

fetch for fetching data to some variable

let user;

const fetchUser = async () => {
  const res = await fetch('/user').then(res => res.json());

  user = res;
};

await fetchUser();

console.log(user);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants