EventBus icon indicating copy to clipboard operation
EventBus copied to clipboard

do not hold lock on whole publish

Open Snawoot opened this issue 2 years ago • 3 comments

Fix #35 Fix #52

This PR does not holds lock during whole publish process. It saves from deadlocks when callbacks also trying to publish something or manage subscription on the bus.

Before this publish worked with copy of active handlers anyway, so now it's safe to work with bus because it uses locks only to manage internal state, not causing deadlock in subsequent calls from handlers.

There is a slight change in the handler object: once boolean flag replaced with pointer to sync.Once. This achieves following goals:

  • Use separate synchronization to ensure handler invoked only once.
  • Uses pointer to allow sync.Once to be nullable and skip it when not needed.
  • Uses uniqueness property of pointers in handlers slice to reliably find own record for removal.

Snawoot avatar Apr 14 '22 21:04 Snawoot

Hello @Snawoot and @millken it seems the PR is not merged. Any reason why?

Tochemey avatar Dec 24 '22 13:12 Tochemey

@Tochemey Because only @asaskevich can merge.

Snawoot avatar Dec 24 '22 13:12 Snawoot

Hello @asaskevich any reason this PR is not yet merged. Also do you advice to still use this library in production because I have not seen any update to it.?

@Tochemey Because only @asaskevich can merge.

Thank you so much @Snawoot

Tochemey avatar Dec 24 '22 13:12 Tochemey