Skip to content

for await from console only works once #5175

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
robobun opened this issue Sep 13, 2023 · 0 comments · Fixed by #5216
Closed

for await from console only works once #5175

robobun opened this issue Sep 13, 2023 · 0 comments · Fixed by #5216
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API

Comments

@robobun
Copy link

robobun commented Sep 13, 2023

I'm using the following code mentioned in the docs to read lines from the console:

async function readInput(): void {
  for await (const line of console) {
    console.log('Reading input.');
    if (line == "break") {
      break;
    }
  }
}

This works well if I run it once, but if I try to read the console input multiple times (by calling readInput in a loop for example), the input isn't read any more after the first iteration and the for await (const line of console) loop isn't called anymore.
Is this a bug or am I doing something wrong?

Example that doesn't work:

async function readInputMultipleTimes(): void {
  for (int i = 0; i < 10; i++) {
    // Only the first readInput() will work properly
    await readInput();
  }
}

Originally reported on Discord: Reading from console using for await (const line of console) only works once

@robobun robobun added bug Something isn't working bun.js Something to do with a Bun-specific API labels Sep 13, 2023
paperclover added a commit that referenced this issue Sep 13, 2023
paperclover added a commit that referenced this issue Sep 14, 2023
paperclover added a commit that referenced this issue Sep 14, 2023
paperclover added a commit that referenced this issue Sep 14, 2023
paperclover added a commit to SuperAuguste/bun that referenced this issue Sep 18, 2023
…g the console iterator (oven-sh#5216)

* Fix oven-sh#5177

* Fix oven-sh#5175

* make most globals deletable/overridable

* not done

* cool

* a

* done

* fix test

* oops

* yippee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API
Projects
None yet
1 participant