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

chore: improve WakuRelay subscribe return value #3222

Open
gabrielmer opened this issue Dec 18, 2024 · 0 comments
Open

chore: improve WakuRelay subscribe return value #3222

gabrielmer opened this issue Dec 18, 2024 · 0 comments
Labels
effort/hours Estimated to be completed in a few hours

Comments

@gabrielmer
Copy link
Contributor

Background

Waku Relay's subscribe returns a wrapped handler which we almost always discard

proc subscribe*(
w: WakuRelay, pubsubTopic: PubsubTopic, handler: WakuRelayHandler
): TopicHandler =

the idea of returning the wrapped handler is so we can then unsubscribe to that specific handler

proc unsubscribe*(w: WakuRelay, pubsubTopic: PubsubTopic, handler: TopicHandler) =
## Unsubscribe this handler on this pubsub topic
debug "unsubscribe", pubsubTopic = pubsubTopic
procCall GossipSub(w).unsubscribe(pubsubTopic, handler)

which is a feature we don't use much, but Waku Relay supports.
We have to wrap the original handler passed to subscribe so it matches the proc signature that GossipSub expects from a handler.

The flow of subscribe returning a handler which we almost always discard or having to save it to pass as a parameter to unsubscribe is a bit cumbersome.

We should review whether we need/want the feature of subscribing and/or unsubscribing specific handlers, and if so, consider a simpler way.

It could be requiring the user to pass a handler in the format that GossipSub expects and avoid wrapping it ourselves, adding a name/id to each set handler so it can be referenced by the unsubscribe procedure, or any other solution that makes us avoid all the unnecessary discards and spares the user from saving a wrapped handler just in case they want to call unsubscribe.

@gabrielmer gabrielmer moved this to To Do in Waku Dec 18, 2024
@gabrielmer gabrielmer added the effort/hours Estimated to be completed in a few hours label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/hours Estimated to be completed in a few hours
Projects
Status: To Do
Development

No branches or pull requests

1 participant