Puzzle 18 Explanation: Go Job
Understand how structures work in Go.
We'll cover the following...
Try it yourself
Try executing the code below to see the result for yourself.
Press + to interact
package mainimport ("fmt")type Job struct {State stringdone chan struct{}}func (j *Job) Wait() {<-j.done}func (j *Job) Done() {j.State = "done"close(j.done)}func main() {ch := make(chan Job)go func() {j := <-chj.Done()}()job := Job{"ready", make(chan struct{})}ch <- jobjob.Wait()fmt.Println(job.State)}
Explanation
At ...
Access this course and 1400+ top-rated courses and projects.