-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref: Avoid some usage of SyncPromise
where not needed
#17641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
size-limit report 📦
|
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
9038bfe
to
77dd72e
Compare
241d7cf
to
61a0aa7
Compare
This changes our fetch transport a bit, making use of async functions and slightly adjusting error handling: 1. Technically there was a bug if fetch is not available, as we would keep increasing the `pendingBodySize`/`pendingCount` and never decrease it. 2. We had some dedicated error messages for edge cases that are IMHO not necessary - we can safe a few bytes by just using default error messages there. 3. No need to use sync promise here, all of this is async anyhow. Extracted this out of #17641
I noticed that we actually handled errors in `sendEnvelope` incorrectly - we would resolve this function with the rejection reason, if sending fails. this does not match the type of `TransportMakeRequestResponse`, you could actually get something like this out (and the tests actually incorrectly tested this): ```js // transport.send() rejects with "fetch does not exist" const res = await client.sendEnvelope(envelope); // res --> "fetch does not exist" (string) ``` This PR fixes this to instead resolve with an empty object (which matches the expected return type). Extracted this out of #17641 because it is actually a bug/fix.
59eeb61
to
b6c7507
Compare
We make quite heavy use of it in event processing, not touching this for now, but in other places it should not be needed IMHO. fix transport using async refactor some more sync promise stuff fix node client fix some flushing stuff fix check oops small fixees fix tests fix lint fix to promise like small ref avoid special casing of no fetch implementation fetch stuff
b6c7507
to
3bc8532
Compare
// @ts-expect-error - PromiseLike is a subset of Promise | ||
public async flush(timeout?: number): PromiseLike<boolean> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for a moment, I thought the async
signature change would still be breaking for anyone currently extending Client
and overriding this method (as in, them not having the async
declaration). But it seems like this is fine (at least with the TS settings in our repo) and TS is smart enough to handle it. Just wanted to leave this thought here in case we can think of a TS setting or a scenario where this might be problematic.
Co-authored-by: Lukas Stracke <[email protected]>
We make quite heavy use of it in event processing, not touching this for now, but in other places it should not be needed IMHO. These are all places that will never be sync generally speaking so it is fine to make them "proper" async.
Somewhat related to #17634