Git Product home page Git Product logo

Comments (2)

yschroe avatar yschroe commented on July 2, 2024

This does only seem to happen, if you use a for await loop, right? For me it works fine with:

rl.on('line', (line) => {
  console.log(typeof line, line)
}

Had a quick look, what might cause the problem with await, and maybe these blocks of code are worth investigating.
As far as I can see, the AsyncIterator of readline uses EventEmitter.on:

bun/src/js/node/readline.js

Lines 2459 to 2469 in a0bcd0f

[SymbolAsyncIterator]() {
if (this[kLineObjectStream] === undefined) {
this[kLineObjectStream] = EventEmitter.on(this, "line", {
close: ["close"],
highWatermark: 1024,
[kFirstEventParam]: true,
});
}
return this[kLineObjectStream];
}
};

In there, the event return value ev is always wrapped in an array, as this is the default behaviour for node.js as well. (Does anyone know why that is? Seems counter intuitive to me.):

bun/src/js/node/events.js

Lines 369 to 375 in a0bcd0f

emitter.on(event, ev => {
if (!unconsumedPromises.isEmpty()) {
const { resolve } = unconsumedPromises.shift();
return resolve([ev]);
}
unconsumedEvents.push([ev]);
});

In node.js' implementation though, setting the option kFirstEventParam: true does skip the array collection step and returns the value as is:
https://github.com/nodejs/node/blob/a8de25ed1523594dd6bf0ee08a24f146d38cb4e8/lib/events.js#L1158-L1160

The kFirstEventParam option does not seem to be implemented in bun at the moment and that's probably why the lines are wrapped in an array in your example.

I do not have a bun dev environment set-up right now to check, so this might be wrong.

Still does not explain why the read-in stops after 3 rows.

from bun.

Electroid avatar Electroid commented on July 2, 2024

Related: #8370

from bun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.