Giter VIP home page Giter VIP logo

Comments (7)

gunar avatar gunar commented on July 20, 2024

I think you got it the other way around. Promises always return a single value (could be an Array of values, of course. see Promise.all()). Callbacks indeed could take more than just (err, value).

from es6-promisify.

kumar303 avatar kumar303 commented on July 20, 2024

I think you got it the other way around.

Was my proposed example incorrect? It was just a sample, the docs could contain any example.

Promises always return a single value

I know but to me it was not totally obvious how es6-promisify would wrap a node-style function that executes a callback with multiple args. If you think it's obvious then feel free to close the bug. It should be easy to document how a callback with multiple args gets wrapped by es6-promisify though, it's only a couple more lines in your docs. You could copy/paste what I added here.

from es6-promisify.

gunar avatar gunar commented on July 20, 2024

I fully agree! 👍 I'd like that documentation and actually I don't even know what es6-promisify does in this case, do you?

I have misread the description of your second snippet: "For those unfamiliar with promises, THEY would expect it to look more like:". Sorry 😄

from es6-promisify.

kumar303 avatar kumar303 commented on July 20, 2024

I don't even know what es6-promisify does in this case, do you?

Yes. My first example is correct, I tried it. You have to use it like this:

import tmp from 'tmp';  // node builtin

let createTmpDir = promisify(tmp.dir);
createTmpDir()
  .then((result) => {
    let [tmpPath, removeTmpDir] = result;
    // ...
  });

from es6-promisify.

mikehall314 avatar mikehall314 commented on July 20, 2024

Pull requests cheerfully accepted :)

from es6-promisify.

kumar303 avatar kumar303 commented on July 20, 2024

Pull requests cheerfully accepted :)

Feel free to close the issue, it was just a suggestion. I don't have time for a patch right now. Maybe later.

from es6-promisify.

kumar303 avatar kumar303 commented on July 20, 2024

This issue can be closed now. I just saw the new multiArg feature and it seems well documented: https://github.com/digitaldesignlabs/es6-promisify#handle-callback-multiple-arguments

FWIW, I don't fully understand this change. Any reason why multiArg: true isn't the default behavior? I can't think of a situation where one would expect it to work like multiArg: false. It seems convenient as a shortcut but it is confusing if you need to reach multiple callback arguments. Anyway, I updated my use of promisify() with {multiArg: true} and it's working fine.

from es6-promisify.

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.