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

Lock aquired when publish an event from subscriber. #52

Open
BhautikChudasama opened this issue Jan 16, 2022 · 1 comment · May be fixed by #53
Open

Lock aquired when publish an event from subscriber. #52

BhautikChudasama opened this issue Jan 16, 2022 · 1 comment · May be fixed by #53

Comments

@BhautikChudasama
Copy link

Current behaviour

The main function Publish an event1 and relative handler of event1, publish event2, but the event2 handler is not calling, and the program is not exited.

bus.Subscribe("event2", func() {
	fmt.Println("event2")
})
bus.Subscribe("event1", func(bus EventBus.Bus) {
	fmt.Println("event1")
	time.Sleep(time.Second * 5)
	bus.Publish("event2")
})
bus.Publish("event1", bus)

Further debugging

  • I had seen in subscribe we lock bus, so whenever publish already locked, and in SubscribeAsync we can't lock bus.
    Is that default behaviour?
@hinora
Copy link

hinora commented Apr 7, 2022

You can do like this

bus.Subscribe("event2", func() {
	fmt.Println("event2")
})
bus.Subscribe("event1", func(bus EventBus.Bus) {
        go func() {
	        fmt.Println("event1")
	        time.Sleep(time.Second * 5)
	        bus.Publish("event2")
        }()
})
bus.Publish("event1", bus)

@Snawoot Snawoot linked a pull request Apr 14, 2022 that will close this issue
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 a pull request may close this issue.

2 participants