feat(core,websockets): use rxjs to check if values are observables#9491
Merged
kamilmysliwiec merged 3 commits intonestjs:9.0.0from May 17, 2022
Merged
feat(core,websockets): use rxjs to check if values are observables#9491kamilmysliwiec merged 3 commits intonestjs:9.0.0from
kamilmysliwiec merged 3 commits intonestjs:9.0.0from
Conversation
Pull Request Test Coverage Report for Build dcbc02b5-7264-47ae-ad61-0d9f89c128bd
💛 - Coveralls |
Member
Author
|
looks like the CI pipeline is broken 🤔 |
98406df to
88575ee
Compare
micalevisk
commented
Apr 23, 2022
| @@ -158,7 +163,7 @@ export class WebSocketsController { | |||
| deferredResult: Promise<any>, | |||
| ): Promise<Observable<any>> { | |||
| const result = await deferredResult; | |||
Member
Author
There was a problem hiding this comment.
btw the tests didn't cover the following
because
await Promise.resolve( Promise.resolve(123) ) return 123 (node16)
Should we drop that if?
88575ee to
bc0a1de
Compare
BrunnerLivio
approved these changes
Apr 26, 2022
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Here's the full code: https://gitlab.com/micalevisk/nestjs-observable-issue
If we return a literal object that has the
subscribemethod on it, the application gets stuckIf we return
req.route(from Express), we got the following error (and500as a response)What is the new behavior?
Instead of checking if the return of the method has the function
subscribe, we're usingisObservablefromrxjsto check if the return is, in fact, a valid observable objectThus, now with the above code the server will reply with this JSON instead:
{ "path": "/", "stack": [ { "name": "<anonymous>", "keys": [], "regexp": { "fast_star": false, "fast_slash": false }, "method": "get" } ], "methods": { "get": true } }as expected.
And just
{}when we return{ subscribe(){} }Does this PR introduce a breaking change?
Other information
There are other places in which
isObservableis used. See:Details
While others are using
isFunction(value.subscribe)and I'm unsure if this was intentional. See:Details
Should we do the same for
nest/packages/microservices/client/client-grpc.ts
Lines 211 to 212 in d9d628d
nest/packages/microservices/client/client-grpc.ts
Lines 154 to 155 in d9d628d
?