-
Notifications
You must be signed in to change notification settings - Fork 765
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
Introduce grpc.web.ClientReadableStreamDelegate #253
Conversation
Thanks for the contribution. We had this discussion internally about this API when we started this project and we kept this API for two reasons:
But I do understand the desire to have more type-safety per se. Is there another library/project where these type of |
Oh, actually, now that I read this again, you are actually not changing the public |
Thanks for your insights. Changing the current I have seen this delegation-pattern style in other libraries before, but I cannot think of a concrete example right now. Having |
Yea looks like this PR does not alter the public API and only offers more type-checking as an implementation details, which I am OK with that. So it looks that you may wan to do the same thing for |
@Yannic Maybe I'm misunderstanding what you mean by "type safe", but it sounds like you're talking about TypeScript typings. Can a similar effect not be achieved using multiple
Again, pardon if I'm misunderstanding the goal here. |
@stanley-cheung Yeah, @jonahbron I'm talking about the type system of google's closure compiler, which uses JSDoc-like comments to declare types. Unfortunately, what you describe isn't possible, at least not with the open-source version of closure-compiler. Haven't seen googles internal version, though. |
c573905
to
ffbedfe
Compare
This CL introduces |grpc.web.ClientReadableStreamDelegate|, a type-safe alternative to |grpc.web.ClientReadableStream.prototype.on|.
ffbedfe
to
cfb84d5
Compare
This is ready for review now. |
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.
npm test
failed. Not sure if you can see the Kokoro test run output, but here's the relevant section:
protoc generated code
✓ should exist
✓ should import
grpc-web generated code (commonjs+grpcwebtext)
✓ should exist
✓ should import
✓ should send unary request
✓ should receive unary response
✓ should receive streaming response
1) should receive trailing metadata
2) should receive error
grpc-web generated code (closure+grpcwebtext)
✓ should exist (5952ms)
✓ should import (39ms)
✓ should send unary request
✓ should receive unary response
grpc-web plugin test, with subdirectories
✓ should exist
✓ should import
✓ should send unary request
grpc-web plugin test, with multiple input files
✓ should exist
✓ should import
16 passing (22s)
I can reproduce it locally.
$ cd packages/grpc-web
$ npm install
$ npm test
Looks like this self.onStatusCallback_
occurance has not been properly replaced?
https://github.com/grpc/grpc-web/blob/master/javascript/net/grpc/web/grpcwebclientreadablestream.js#L166
Maybe there's some other too. Please look into that. Thanks!
|
||
goog.module.declareLegacyNamespace(); | ||
|
||
// const Error = goog.require('grpc.web.Error'); |
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.
Is this still needed?
goog.module('grpc.web.StreamBodyClientReadableStreamTest'); | ||
goog.setTestOnly(); | ||
|
||
var GrpcWebStreamParser = goog.require('grpc.web.StreamBodyClientReadableStream'); |
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.
Variable should be renamed?
Looking at this again, I'm starting to get some mixed feelings whether we should really add this because it may not be the best idea to have two seperate APIs on one class doing the exact same thing. I think it would be better to have a compiler option choosing between two seperate implementations. Leaving this open for now, I will post some more information about this plan soon (Hopefully also helping what's asked in #260). |
The write to the CloseNotify() channel was blocking, preventing the Read() call from exiting, and preventing ServeHTTP from returning. This meant that requests tended to stay around forever in a deadlocked state. Using the context package prevent this, as the cancellation is non-blocking. It depends on Go 1.7. Note that the writer still needs to support the CloseNotifier interface, otherwise other things break, but it does not seem to be necessary to signal using it.
This CL introduces
grpc.web.ClientReadableStreamDelegate
, a type-safealternative to
grpc.web.ClientReadableStream.prototype.on
. This is animprovement for type-checking of clients which currently need to suppress
reportUnknownTypes
.