Standard library / runtime
runtime.Goexit()
Terminates only the calling goroutine, running its deferred functions. It is not a panic and does not terminate the process. Expected stdout: 'done\n'.
Formal Syntax & Structure
go syntaxgo
func Goexit()Working Example
Example Snippetgo
package main
import ( "fmt" "runtime")
func main() { done := make(chan struct{}) go func() { defer close(done); runtime.Goexit(); fmt.Println("unreachable") }() <-done fmt.Println("done")}