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

Mechanism for removing connection onClose callback #229

Open
viglucci opened this issue May 28, 2022 · 0 comments
Open

Mechanism for removing connection onClose callback #229

viglucci opened this issue May 28, 2022 · 0 comments
Labels
1.0 Pullrequests & issues related to the Typescript rewrite and 1.0 release enhancement Suggests, requests, or implements a feature or enhancement

Comments

@viglucci
Copy link
Member

We can register a callback with an RSocket using the onClose method. We do not currently have any way to deregister a previously registered callback.

Motivation

I'm sure there are other use cases, however, this would be useful when paired with the useEffect hook in React, which expect to be able to "undo" registrations and side-effects.

useEffect(() => {
  const id = rsocket.onClose((e) => {
    console.log(e);
  });
  return () => {
    rsocket.removeCloseListener(id);
  };
}, [rsocket]);

Desired solution

RSocket, likely through Closeable, could be extended to allow deregistration of callbacks. This might be best with having Closeable more closely resemble event emitter APIs.

// add a listener
const id = rsocket.onClose.addEventListener(() => {...});

// remove a listener
rsocket.onClose.removeEventListener(id);

Considered alternatives

Rsocket.onClose could implement/expose an observable that would natively support subscriptions. This could use existing types such as Cancellable and OnTerminalSubscriber.

@viglucci viglucci added enhancement Suggests, requests, or implements a feature or enhancement 1.0 Pullrequests & issues related to the Typescript rewrite and 1.0 release labels May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0 Pullrequests & issues related to the Typescript rewrite and 1.0 release enhancement Suggests, requests, or implements a feature or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant