GithubHelp home page GithubHelp logo

Every CATCH has an IF about await-to-js HOT 11 CLOSED

scopsy avatar scopsy commented on May 11, 2024
Every CATCH has an IF

from await-to-js.

Comments (11)

AckerApple avatar AckerApple commented on May 11, 2024 1

Pull request #34 submitted.

If this was my package, I would just remove the second argument and its accompanying logic. The extra argument isn't even documented so no one but you is most likely even using it.

Please thoroughly consider my request. Your await-to-js is the best approach of the 3 packages on npm and I don't want to release a 4th just over this errorExt argument.

Thank you kindly

from await-to-js.

JohnForster avatar JohnForster commented on May 11, 2024 1

@AckerApple The to library can be written in one line of code.

const to = promise => promise.then(x => [null, x]).catch(e => [e])

You don't need a library for this, a util file will do.

from await-to-js.

ComBarnea avatar ComBarnea commented on May 11, 2024

@AckerApple in that case you will end up loosing the error, right? What will you do if something did happen and there is no answer?

from await-to-js.

AckerApple avatar AckerApple commented on May 11, 2024

I don't think you are understanding me correctly.

Why do you have this extra argument? (rhetorical question)
https://github.com/scopsy/await-to-js/blob/master/src/await-to-js.ts#L8

Why support such a feature in this unit test? (rhetorical question)
https://github.com/scopsy/await-to-js/blob/master/test/await-to-js.test.ts#L24

The extra argument "errorExt" is a distasteful hit against performance. Every catch, will result in an IF condition being processed even though never needed.

I work for FirstData (now Fiserve) and we processes hundreds of thousands of records every couple of hours for payment processing. We have a lot of async/awaits that resolve in catches as we have our validations throw errors. I can't adopt this package into our company without addressing this IF that runs with every catch.

I would like to remove the extra argument OR add an additional function that has no second argument.

Understand? I'm in Florida preparing for a storm. At some point I'll just issue the pull request.

from await-to-js.

AckerApple avatar AckerApple commented on May 11, 2024

@ComBarnea

I suppose you are trying to ask me is: What if a promise is rejected with like Promise.reject(null), right? Meaning, what if a rejection happens and NOTHING is returned. Is that what you are asking?

Who does that? The concept of failure without a reason, that's terrible. But I suppose you are saying it can happen.

IF that's what you're asking me, then your code is NOT going to handle that type of situation.

The code on this line uses an Object.assign().
https://github.com/scopsy/await-to-js/blob/master/src/await-to-js.ts#L14

IF you try to use Object.assign(null, {something:22}) on a null or undefined object an error of "Uncaught TypeError: Cannot convert undefined or null to object" occurs.

from await-to-js.

adi518 avatar adi518 commented on May 11, 2024

@AckerApple At this point, #34 will probably never get merged. See this. No If condition there. Although I like the array destructure pattern more, that one returns an object. There might be room for one more package, one that returns an array without the extra jab.

from await-to-js.

AckerApple avatar AckerApple commented on May 11, 2024

@adi518 thank you so much. That package looks almost great other than it has a dependency on @babel/polyfill for seemingly no reason.

As seen here: https://github.com/krlozadan/a-promise-wrapper/blob/master/src/index.js

from await-to-js.

adi518 avatar adi518 commented on May 11, 2024

Ah yes, I did notice that too. He made a mistake adding it. Stuff like that should be added by consumers. It's worth starting an issue, or, unless npm has absolutely no more options, I'll just make a new one that combines the good and leaves out the bad.

from await-to-js.

AckerApple avatar AckerApple commented on May 11, 2024

Thank you and yes that would do. It’s not data typed so often that one liner is gonna lead to “any” translations but yeah it works.

from await-to-js.

JohnForster avatar JohnForster commented on May 11, 2024

@AckerApple

const to = <T>(promise: Promise<T>): Promise<[null | Error, T | undefined]> =>
  promise
    .then((res) => [null, res] as [null, T])
    .catch((e) => [e, undefined] as [Error, undefined]);

if you need type safety

from await-to-js.

AckerApple avatar AckerApple commented on May 11, 2024

Well done. Gonna move that code into my own package and install everywhere I was using this package. If it was a one liner than yeah maybe I copy paste for every use.

We stopped using this code package a long time ago and ONLY because it had an unnecessary IF that is a major performance hit when batch processing millions of financial records (FirstData)

from await-to-js.

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.