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

"complete" single fired events? #181

Open
benlesh opened this issue Oct 21, 2024 · 2 comments
Open

"complete" single fired events? #181

benlesh opened this issue Oct 21, 2024 · 2 comments

Comments

@benlesh
Copy link
Collaborator

benlesh commented Oct 21, 2024

For example, if you have a web socket, and you get a close event, I'm proposing that we just complete it for the user. This of course means identifying different things that are like this and handling them appropriately.

const socket = new WebSocket('wss://whatever');

socket.when('close').subscribe({
  next: () => console.log('closed'),
  complete: () => console.log('done'),
});

AbortSignal's abort is another one I can think of off the top of my head.

Alternatively, users will just have to add a take(1) to them.

But this does illustrate another advantage to Observable over addEventListener. It also causes the subscription to teardown and clean up, which can cascade through flatMap and other composition.

@domenic
Copy link
Collaborator

domenic commented Oct 22, 2024

I can see arguments both ways on this. One potential issue is, how does this react to socket.dispatchEvent(new Event("close"))?

@benlesh
Copy link
Collaborator Author

benlesh commented Oct 24, 2024

I would assume it would still fire once, then complete. For consistency.

Of course, subscribing again would start waiting for a new close event. But that's interesting.

I guess we would have to look at use cases for dispatching close events manually

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

2 participants