Skip to content
This repository was archived by the owner on Mar 31, 2018. It is now read-only.
This repository was archived by the owner on Mar 31, 2018. It is now read-only.

How promise APIs would look like in core #16

@balupton

Description

@balupton

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:

Current / unresolved discussions:

  • do any of the active proposals support callbacks at all? if so, when, why and how? if not, why or when?
  • require('fs/promise').readFile initially, or require('fs').readFilePromise initially
    • arguments regarding require('fs/promise').readFile initially and perhaps only
      • +1 works better with ES6 imports Adding Core support for Promises node#5020 (comment)
      • +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.]
      • -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.]
      • [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
    • 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
  • 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

Proposals 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]

// 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.]
await fs.readFilePromise('some/file', {
  ENOENT() {
    return null
  }
})

// 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.]
let file = await fs.getFileAsync('dne').recover({
   EISDIR(err) {}
   ENOENT(err) { ... }
});

Proposals for new APIs:

[CD - these probably will not land in nodejs/node#5020].


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.]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions