node-csvtojson icon indicating copy to clipboard operation
node-csvtojson copied to clipboard

RFC: dropping Bluebird

Open MatthewHerbst opened this issue 6 years ago • 5 comments

Would you be open to dropping Bluebird in favor of native promises? I would be happy to write the PR to do this. It would be a breaking change.

MatthewHerbst avatar Sep 02 '19 11:09 MatthewHerbst

This would be nice since I think I've run into an issue due to this. I have code like so:

const data = csv().fromFile('my-data.csv'))

async function doSomeStuff (name) {
  await data

  return data.find(d => d.name === name)
}

The await hangs. It also hangs if I try data.then(). IIRC this works fine with the standard promise implementation.

evanshortiss avatar Sep 09 '19 21:09 evanshortiss

@MatthewHerbst Yes. for longer term, native promise is preferred. However csvtojson only uses bluebird internally -- I think no API that returns a Promise object. Could you please let me know what is the reason to replace bluebird?

@evanshortiss Oh.. That is a bug! csv() returns a Thennable object. It does not actually return Bluebird or native promise. However, it has optimisation to check if final result needs to be built. That is if .then or .subscribe or .on('data') or await is not called before first result, it will not build final result to save memory. Would you please shoot a bug on this?

Thanks. Keyang

Keyang avatar Sep 10 '19 17:09 Keyang

@Keyang thanks for replying. Two reasons. The first is to reduce dependency bloat: no reason to ship Bluebird to clients when clients already know about Promises. The second is for consistency to reduce bugs, as @evanshortiss noticed. For example, I see in my webpack builds hundreds of lines of:

Warning: .then() only accepts functions but was passed: [object Object]

That comes from some library (not necessarily this one) passing the wrong thing to a Bluebird promise.

MatthewHerbst avatar Sep 10 '19 18:09 MatthewHerbst

Agree! Maybe we should look at dropping bluebird support. Avoids dependency bloat as well :). It would be a breaking change.

jeremyrajan avatar Apr 08 '20 13:04 jeremyrajan

This would be nice since I think I've run into an issue due to this. I have code like so:

const data = csv().fromFile('my-data.csv'))

async function doSomeStuff (name) {
  await data

  return data.find(d => d.name === name)
}

The await hangs. It also hangs if I try data.then(). IIRC this works fine with the standard promise implementation.

Was so glad to see you mention this and I'm not alone, this just killed my morning :D

ebgranger avatar May 26 '20 17:05 ebgranger