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

Provide a thread-safe way for a Consumer to access its Registration #44

Closed
wilkinsona opened this issue May 20, 2013 · 2 comments
Closed

Comments

@wilkinsona
Copy link

A Consumer's Registration is returned when the Consumer is passed to Reactor.on. As things stand, if the Consumer wants to access its own Registration it cannot do so without being at risk of a race condition: the Consumer's accept() method may be called before Reactor.on has returned so it won't have access to its Registration.

One solution would be for a Consumer to optionally implement RegistrationAware and have the registry pass the Registration to the Consumer before it's actually added to the registry - this would ensure that the Registration is set before accept can be called.

@gembin
Copy link

gembin commented Oct 12, 2013

But, if i need to cancel it only if some conditions are satisfied, not necessarily cancel after use, how to handle this?

for example:

new Consumer<Event<?>>() {
  @Override
  public void accept(Event<?> e) {
      if(some conditions are satisfied){
          registration.cancel();
      }
  }
})

@jbrisbin
Copy link

instead of registration.cancel(), throw a CancelConsumerException. The Dispatchers will catch this specifically and remove the registration.

@smaldini smaldini closed this as completed Aug 1, 2014
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

4 participants