Skip to content

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

@amin78tech

Description

@amin78tech

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions