Skip to content
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

Can you please add usage example ... #47

Open
martin-mucha opened this issue Nov 4, 2016 · 5 comments
Open

Can you please add usage example ... #47

martin-mucha opened this issue Nov 4, 2016 · 5 comments

Comments

@martin-mucha
Copy link

Hi,

Can you please add usage example ...
I tried to use:

let websocket = new $WebSocket("…");
let observable: Observable = this.websocket.send("test");
observable.subscribe(
value=>console.log("nextValue: " + value),
err=>console.log("error: " + err),
()=>console.log("done.")
);

message arrives to backend, it's returned (to other client), but nothing is logged in console here. Same for using subject.

By using following instead of that:

this.websocket = new $WebSocket("ws://localhost:8280/gerrit-helper/test-websocket-endpoint");
this.websocket.onMessage(function (e) { console.log(e); }, null);
let observable: Observable = this.websocket.send("test");
and subscription to cold observable...

this 'works', but seems really wrong. Why does subscription in first excerpt does not work? (when using Observable.range to verify it seems to work as expected).

Thanks.

@martin-mucha
Copy link
Author

I noticed several nice things in component, so I gave it a more effort to understand it.

I'm quite new to whole js world and not that familiar with rx, but following code from send method ...

return Observable.create((observer) => {
            if (self.socket.readyState === self.readyStateConstants.RECONNECT_ABORTED) {
                observer.next('Socket connection has been closed');
            } else {
                self.sendQueue.push({ message: data });
                self.fireQueue();
            }
        });

is surprising for me. Lets assume, that we've been 'sending' messages, but destination was in failure, so messages just accumulated. Now finally destination went up. We send yet another message, using send as with previous messages.

Issues:

  1. Send message creates observable and does nothing, until we subscribe. That could be OK. But after we subscribe with observer, we will get only failures from that observable.
  2. if we do not get failure during call immediately, we won't get anything else in future, and whole subscription is pointless
  3. even if we do not get anything else in future, observer.complete is not called.
  4. even if we assume, that produced messages are produced using observer.next, and errors are correctly reported using observer.error, and complete is called as well ... it still will be problematic, since subscription to send may produce nothing, while another send may produce totally irrelevat serie of messages, while caller would probably expect, only get responses to his message from subscription origination upon his call...

@bkdotcom
Copy link

bkdotcom commented Nov 9, 2016

"Send message creates observable and does nothing, until we subscribe."
I just spent a fair amount of time tracking that down... arg!!!

Looks like the change happened back in july?
0e38070

See also Issue #41

@martin-mucha
Copy link
Author

that's true, but it's not inconvenience. It's fundamentally wrong I believe. Since you're not subscribing to response (what I'd expect, but that would require doing some pairing request/response which is not present). You're subscribing to 'error stream', which is counterintuitive. And this stream produces items rarely and never completes. This made me to rewrite this tool for myself...

@bkdotcom
Copy link

I might be reading issue #41 and its comments wrong, but I think the consensus is "it's wrong"

@jquince
Copy link

jquince commented Nov 15, 2017

The pattern from the example doesn't work.
Only complete ever gets called even though inspecting the traffic you can see the response come back ok.
ws.send("some thing").subscribe(
(msg)=> {
console.log("next", msg.data);
},
(msg)=> {
console.log("error", msg);
},
()=> {
console.log("complete");
}
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants