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

When I subscribe to a topic and create a function within a goroutine inside the subscription handler, it doesn't close after completing its task. #699

Open
amin78tech opened this issue Dec 13, 2024 · 1 comment

Comments

@amin78tech
Copy link

amin78tech commented Dec 13, 2024

step one:

fmt.Println("start")
go runTest(Service, Provider, contentTopic, 1, time.Second*5)

step two:

func runTest(Service *services.Service, provider *provider.Provider, topic string, qos int, timeout time.Duration) {
 fmt.Println("subscribe func one")
 token := Service.Mqtt.Client.Subscribe(topic, byte(qos), func(client mqtt.Client, msg mqtt.Message) {
 fmt.Println("subscribe func two")
  if data["type"] == "test" {
   runFunc()
   return
  }
 return
}

The first time, all logs are shown from start to finish, but from the second time onward, it only starts logging when I publish content to the topic, starting from:
fmt.Println("subscribe func one")
How can I stop this subscription from continuing?

@MattBrittan
Copy link
Contributor

Sorry I dont really understand your issue. Please see the readme for the suggested info to include. Including actual output would help, as would providing a reproducable example.

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

2 participants