medikoo / deferred

Modular and fast Promises implementation for JavaScript
ISC License
365 stars 20 forks source link

Add a note in the README whether it is advised to use fs2 or Node promisified methods #20

Open madarche opened 10 years ago

madarche commented 10 years ago

Hello,

Happy and grateful user of deferred I have just discovered https://github.com/medikoo/fs2

Is it recommended to use a) var readFile = require('fs2').readFile; or b) var readFile = promisify(fs.readFile, 1); ?

Thanks!

medikoo commented 10 years ago

Hello @madarche,

I use fs2 in most cases, and would recommend to do that, but it's also important to see that fs2 is not only about returning promises, there are many other things that it offers over native fs.

Also it's important to note one limitation in the way how functions are promisified in fs2. They won't auto-resolve input arguments as function generated bypromisify do, e.g. following works great:

var readFile = promisify(fs.readFile), writeFile = promisify(writeFile);
writeFile(__filename + '.copy', readFile(__filename)).done();

but following won't:

var readFile = fs2.readFile, writeFile = fs2.writeFile
writeFile(__filename + '.copy', readFile(__filename)).done();  // Fail

With fs2 functions, you need to do:

readFile(__filename)(function (content) {
  return writeFile(__filename + '.copy', content);
}).done();

I plan to fix that, and then indeed it'll be good idea to mention it in a doc.

madarche commented 10 years ago

Thanks very much @medikoo. I'm now following fs2 closely to know when that happens.

Cheers!