-2

I'm new to Go. I'm trying out this example where I want to perform a concurrent call from a method. This isn't working for me (I don't see the output).

Based on "Effective Go", it says concurrency is supported for methods and functions. What am I doing wrong?

Thanks, -Srikanth

package main

import (
    "fmt"
)

type Hello struct {
    a int
}

func (h *Hello) Myprint (value string) {
    go func() {
        fmt.Println(value)
    } ()
}

func main() {
    h := &Hello{100}

    go h.Myprint("need to go")
}

1 Answers1

0

Your main exits and the process dies before the goroutine has a chance to print the output.

snap
  • 2,751
  • 22
  • 33