Skip to content

Conversation

nathanl
Copy link
Contributor

@nathanl nathanl commented Jun 25, 2025

Given that the possibility of duplicate subscriptions was already discussed in the docs on subscribe/3, I assume there's a performance cost to checking for existing subscriptions that callers may not always want to pay. If so, I'd be happy to document that on subscribe_once/3. But it seems useful to have this function; I'm looking at a use case where the number of subscriptions to a topic won't be large but duplicate messages would be problematic.

Currently, any caller who wants to avoid duplicate subscriptions would need to use some kind of workaround, such as:

  • Avoid calling subscribe/3 more than once by tracking subscriptions in their own process state, or by checking Registry.lookup/2 directly (relying on an implementation detail of PubSub)
  • Call unsubscribe/2 each time before calling subscribe/3

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

Successfully merging this pull request may close these issues.

1 participant