Replies: 1 comment 2 replies
-
Just as an idea, it would be nice if RxJS supported such a uniplex request that returns a promise, accepts a filter and timeout e.g. ws$: WebSocketSubject<Message>
const requestPromise = this.ws$.uniplex(reqMsg, filter, timeout)
requestPromise()
.then(console.log)
.catch(console.error) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to create a simple promise that resolves after the first response and rejects when an error or timeout occurs.
The use case is a request sent to the server via
WebSocketSubject
that responds with a single message. I realize this is a typical HTTP style use case, however we supply streams and simple request-response methods via our WebSocket API.I started using the
Observable.toPromise()
method thinking this would be a great match. However it only resolves after the Observable completes and then it would take the last value in the stream. However I can't complete theWebSocketSubject
as this will kill all subscriptions. Given that I cant really change the inner workings of the Observable to complete after the first response, I just wrapped the subscription in a promise.I'm not delighted with my current solution so I was wondering what the best way to achieve this is?
Here is my current solution:
Beta Was this translation helpful? Give feedback.
All reactions