Testing Goroutine That My Code Does Not Wait For -


I have a function that is executed simultaneously, it is to run a command line method, if any one If so, is entering the error. My main thread of execution does not wait to end this method. It just comes back optimally.

How can I test do my work? Assuming that I give it to cmdStr , such as {"sleep", "1"} , that works, but does not return immediately, How can I wait to finish this ceremony?

I want to make sure that this actual program runs no it has to wait to finish it.

  func runCmd (cmdStr [] string, errChan chan error) {cmd: = exec.Command (cmdStr ...) var bytes. Buffer cmd.Stdout = & amp; Err: = cmd.start () If mistake! = Nil {errChan & lt; - err return} // command successfully started, so our caller can continue. ErrChan & lt; -nil err = cmd.Wait () If mistake! = Zero {log. Print line (fault)}}   

Use a waiting group < Pre> wg: = sync.WaitGroup {} errc: = make (chan error) wg.Add (1) go func () {(CRD) {} sleep {"sleep", 1}, errc) wg. Done ()} () error & lt; Error - errc! = Nil {// handle error} wg.Wait ()


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -