Skip to content

Instantly share code, notes, and snippets.

@kougazhang
Created December 19, 2021 11:14
Show Gist options
  • Save kougazhang/35b6d8c7f404899f02f88e3d7633e2f4 to your computer and use it in GitHub Desktop.
Save kougazhang/35b6d8c7f404899f02f88e3d7633e2f4 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
ben := &Ben{name: "Ben"}
jerry := &Jerry{name: "Jerry"}
var maker IceCreamMaker = ben
var loop0, loop1 func()
loop0 = func() {
maker = ben
go loop1()
}
loop1 = func() {
maker = jerry
go loop0()
}
go loop0()
for {
maker.Hello()
}
}
type IceCreamMaker interface {
Hello()
}
type Ben struct {
id int
name string
}
func (b *Ben) Hello() {
fmt.Printf("Ben: Hello, My Name is %s\n", b.name)
}
type Jerry struct {
name string
}
func (j *Jerry) Hello() {
fmt.Printf("Jerry: Hello, My Name is %s\n", j.name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment