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

Problem with sample program in Async Generators and Iterators article #1775

Open
paroche opened this issue Feb 29, 2020 · 3 comments
Open

Problem with sample program in Async Generators and Iterators article #1775

paroche opened this issue Feb 29, 2020 · 3 comments

Comments

@paroche
Copy link
Collaborator

paroche commented Feb 29, 2020

In Plunker, following Open in Sandbox link, code provided under "An example of use (shows commit authors in console):" doesn't work (because it doesn't include fetchCommits function).

Console shows error:

(index):9 Uncaught (in promise) ReferenceError: fetchCommits is not defined
(index):9 Uncaught (in promise) ReferenceError: fetchCommits is not defined
    at (index):9
    at (index):18

Running the code directly from the run link in article also doesn't work. Gives error:

holder-2.2.min.js:10 Uncaught TypeError: Cannot read property 'appendChild' of undefined
    at Object.e.run (holder-2.2.min.js:10)
    at holder-2.2.min.js:10
    at XMLDocument.h (holder-2.2.min.js:10)

Code in question:

(async () => {

  let count = 0;

  for await (const commit of fetchCommits('javascript-tutorial/en.javascript.info')) {

    console.log(commit.author.login);

    if (++count == 100) { // let's stop at 100 commits
      break;
    }
  }

})();
@joachimklug
Copy link
Contributor

Hi @paroche,
the error is raised as fetchCommits() is a custom function (not part of the standard JavaScript language). This means this function needs to be defined before calling.

On javascript.info this is already included in the header which you can find here

Also the tutorial shows this function in the code snippet above the one you describe. So if you want to execute the code on plunker you need to copy/paste this dependent code as well.

@iliakan
Copy link
Member

iliakan commented Jun 21, 2020

Maybe add a note about "where to find fetchCommit into the example, to avoid confusion?

@paroche
Copy link
Collaborator Author

paroche commented Jun 22, 2020

Hi @joachimklug

Yes, that's what I said in the first line of my post:

"In Plunker, following Open in Sandbox link, code provided under "An example of use (shows commit authors in console):" doesn't work (because it doesn't include fetchCommits function)."

@iliakan -- that would help, though I would think you would want the "Open in Sandbox" link to work.

joaquinelio added a commit to joaquinelio/en.javascript.info that referenced this issue Apr 11, 2021
iliakan added a commit that referenced this issue Apr 17, 2021
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

No branches or pull requests

3 participants