Comments (11)
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.
@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.
@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.
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.
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.
@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.
@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.
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.
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.
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.
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)
- UnhandledPromiseRejectionWarning on Promise error HOT 1
- Error while using KnexJS HOT 1
- Idiomatic go-lang motivation is not readily avaible HOT 1
- Typescript Typings To Use Conditional Logic HOT 9
- No function syntax provided, no errorExt explanation provided HOT 1
- ESLint prints a warning if error isn't used. HOT 2
- thanks author, you may want to use decorater to catch your error~ HOT 1
- Does not work with Promise.promisify HOT 2
- Not catching sync errors
- Runs twice HOT 1
- promise.reject() no params error always undefined HOT 2
- 😎-er Name: await-try-catch HOT 2
- Why version 3? HOT 4
- How to use this with mongoose's Query type? HOT 1
- TypeError: to is not a function HOT 3
- Error not set correctly HOT 2
- 如果想获取error里面的信息怎么办? HOT 1
- what's difference between v2 and v3 HOT 1
- Add named export for more convenient usage for applications using ES modules HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from await-to-js.