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

Implement subscription pooling in web3.js/connection #24176

Closed
steveluscher opened this issue Apr 7, 2022 · 2 comments
Closed

Implement subscription pooling in web3.js/connection #24176

steveluscher opened this issue Apr 7, 2022 · 2 comments
Assignees
Labels
javascript Pull requests that update Javascript code

Comments

@steveluscher
Copy link
Contributor

Problem

If two callers subscribe, for instance, using onAccountChange() for the exact same address, we set up two subscriptions.

Proposed Solution

Implement subscription pooling.

Create a map of people who care about a given subscription:

const accountChangeListeners: Map<
  string,  // Pubkey
  AccountChangeCallback[]
> = new Map();

When that list of callbacks goes from zero to one, set up the subscription. When it falls from 1 to zero, unsubscribe.

When a subscription publishes a payload, broadcast it to all of the callbacks.

@steveluscher steveluscher self-assigned this Apr 7, 2022
@steveluscher steveluscher added the javascript Pull requests that update Javascript code label Apr 7, 2022
@nilpferdschaefer
Copy link

nilpferdschaefer commented Apr 22, 2022

I second this - was just looking at this issue and handling it locally at the moment! Subscription pooling would be great.

@steveluscher
Copy link
Contributor Author

Nice! Any feedback on our implementation @LeFinc? #24473.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code
Projects
None yet
Development

No branches or pull requests

2 participants