How to use callbacks in golang?

I need to use go threads infinite time.

Hi. I’m not really sure what you want to accomplish. Could you be more specific?

There isn’t any “go threads” in Go, there are “Go Routines”.

To terminate a single goroutine just send it a signal, like this:

package main

import (
	"fmt"
	"time"
)

func main() {
	signal := make(chan struct{})
	go func() {
		fmt.Println("waiting")
		<-signal
	}()

	// wait for 5 secs then send the signal
	time.Sleep(time.Second * 5)

	// close will unblock every receiver
	fmt.Println("sending the signal")
	close(signal)
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.