Question:

Explain what is go routine in GO? How you can stop go routine?

Answer:

A goroutine is a function which is capable of running concurrently with other functions

To stop goroutine, you pass the goroutine  a signal channel, that signal channel is used to push a value into when you want the goroutine to stop.  The goroutine polls that channel regularly as soon as it detects a signal, it quits.

Quit : = make (chan bool)

go func ( ) {

	for  {

		select {

			case <- quit:

			return

			default

// do other stuff

		}

	}

}()

// Do stuff

// Quit goroutine

Quit <- true

 


Keywords:

© 2017 QuizBucket.org