...

/

Puzzle 18 Explanation: Go Job

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 main
import (
"fmt"
)
type Job struct {
State string
done 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 := <-ch
j.Done()
}()
job := Job{"ready", make(chan struct{})}
ch <- job
job.Wait()
fmt.Println(job.State)
}

Explanation

At ...

Access this course and 1400+ top-rated courses and projects.