You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 31, 2018. It is now read-only.
Proposing this thread to consolidate the various discussions and proposals around "How promise APIs would look like in core." as the original pull request covers more than just that sole issue, making it hard to keep track of what is actually being proposed. Feel free to edit. [CD: Thanks!]
+1 allows blacklisting How promise APIs would look like in core #16 (comment) [CD: For top level methods, yes, but not for class instance methods. Still best to block promises using global.Promise = null in all cases.]
[CD: my concerns with blocking the merge of 5020 on this approach.]
-1 unclear on what to do for instance methods (net.Socket#setTimeout)
-1 unclear on whether or not to re-export non-promise-returning methods (fs.createReadStream)
-1 difficult to drive consensus within collaborator group on whether or not to add submodule
-1 difficult to drive consensus on what to call the module (promised is a frontrunner, since we have the name, but this is a potential for bikeshedding)
arguments regarding require('fs').readFilePromise with or without require('fs').promised.readFile shortcut initially
[CD: the promised shortcut works for destructuring assign, import x as y syntax should work for ES2015 modules].
-1 despite being in the PR, no consensus has formed yet, also if support is added for all three (not just require('fs/promise') then maintaining 3 endpoints that all do the same thing is pain Adding Core support for Promises node#5020 (comment)
are there any arguments differentiating between require('fs').readFilePromise and require('fs').promised.readFile, why one or the other?
should promises wrap callback functions, or should callback functions wrap promise functions (initially or later)
Closed proposals:
Promise only: require('fs').readFile returns promises only, no support for callback — one API endpoint to maintain, b/c break for everyone, consistent return types, promises are primary and callbacks are eliminated, could provide cleanest forward API
Callback or promise: require('fs').readFile returns promise if no callback is provided, if callback is provided do not return promise and use callback — one API endpoint to maintain, performance hit with additional if check, different return types, callbacks or promises become secondary to the other
argument against here Adding Core support for Promises node#5020 (comment) as it will cause issues with things like process.send(message[, sendHandle][, callback]) which can have a return value despite having an async callback, changing return value to promise will break b/c with current return value
Promise always with callback support: require('fs').readFile returns promise always, if callback is provided attach it to the promise — one API endpoint to maintain, performance hit for callback users, consistent return types, promises are primary and callbacks become secondary
argument against here Adding Core support for Promises node#5020 (comment) as it will cause b/c breaks with things like process.send(message[, sendHandle][, callback]) which can have a return value despite having an async callback, changing return value to promise will break b/c with current return value
[CD - There may not need to be an error API — it might look like a flag, like --abort-on-sync-rejection]
// https://github.com/nodejs/promises/issues/10#issue-133802245// recovery object// [CD - It appears likely that we'll go this route since error symposium folks have raised concerns about it.]awaitfs.readFilePromise('some/file',{ENOENT(){returnnull}})// normal use:fs.readFilePromise('some/file')
// https://github.com/nodejs/promises/issues/10#issuecomment-184375707// [CD - It's unlikely that we'll go this route because I'd like to avoid subclassing Promise.]letfile=awaitfs.getFileAsync('dne').recover({EISDIR(err){}ENOENT(err){ ... }});
The other issue "How to make sure promises don't get in the way of callback users with core support." seems like a sub-topic of "How promise APIs would look like in core". So perhaps that should be consolidated here too. [CD - Promises will be added using a promisify wrapper, without affecting the original function. They should not interfere with callback APIs at all.]
Proposing this thread to consolidate the various discussions and proposals around "How promise APIs would look like in core." as the original pull request covers more than just that sole issue, making it hard to keep track of what is actually being proposed. Feel free to edit. [CD: Thanks!]
Proposals for current APIs:
Active proposals:
require('fs').readFilePromise(current PR proposal) +require('fs').promised.readFileshortcutAdding Core support for Promises node#5020 (comment)
require('fs/promise').readFile(future PR proposal) (to immediately follow 5020 once landed)Current / unresolved discussions:
require('fs/promise').readFileinitially, orrequire('fs').readFilePromiseinitiallyrequire('fs/promise').readFileinitially and perhaps only+1 allows blacklisting How promise APIs would look like in core #16 (comment)[CD: For top level methods, yes, but not for class instance methods. Still best to block promises usingglobal.Promise = nullin all cases.]-1 requires PR to be updated How promise APIs would look like in core #16 (comment)[CD: I am not concerned about changing the PR.]net.Socket#setTimeout)fs.createReadStream)promisedis a frontrunner, since we have the name, but this is a potential for bikeshedding)require('fs').readFilePromisewith or withoutrequire('fs').promised.readFileshortcut initiallypromisedshortcut works for destructuring assign,import x as ysyntax should work for ES2015 modules].require('fs/promise')then maintaining 3 endpoints that all do the same thing is pain Adding Core support for Promises node#5020 (comment)require('fs').readFilePromiseandrequire('fs').promised.readFile, why one or the other?Closed proposals:
require('fs').readFilereturns promises only, no support for callback — one API endpoint to maintain, b/c break for everyone, consistent return types, promises are primary and callbacks are eliminated, could provide cleanest forward APIrequire('fs').readFilereturns promise if no callback is provided, if callback is provided do not return promise and use callback — one API endpoint to maintain, performance hit with additional if check, different return types, callbacks or promises become secondary to the otherprocess.send(message[, sendHandle][, callback])which can have a return value despite having an async callback, changing return value to promise will break b/c with current return valuerequire('fs').readFilereturns promise always, if callback is provided attach it to the promise — one API endpoint to maintain, performance hit for callback users, consistent return types, promises are primary and callbacks become secondaryprocess.send(message[, sendHandle][, callback])which can have a return value despite having an async callback, changing return value to promise will break b/c with current return valueProposals for error APIs:
Discussion ongoing at #10, summary:
[CD - There may not need to be an error API — it might look like a flag, like
--abort-on-sync-rejection]Proposals for new APIs:
[CD - these probably will not land in nodejs/node#5020].
util.promised:util.promised- Callbacks and async/await #5util.toCallback:util.toCallback(asyncFn)- interop of async functions with callbacks. #6The other issue "How to make sure promises don't get in the way of callback users with core support." seems like a sub-topic of "How promise APIs would look like in core". So perhaps that should be consolidated here too. [CD - Promises will be added using a promisify wrapper, without affecting the original function. They should not interfere with callback APIs at all.]