Created
September 7, 2018 17:45
-
-
Save aj0strow/7cb847e8ddc9c20b3d42738329314d1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type whyNeedPointer struct { | |
Do func(string) | |
} | |
func main() { | |
doStuff := func(s string) { | |
fmt.Println(s) | |
} | |
w := whyNeedPointer{ | |
Do: doStuff, | |
} | |
w.Do("why need ptr?") | |
nextDo := make(chan func(string)) | |
go func() { | |
nextDo <- func(s string) { | |
fmt.Printf("next %s\n", s) | |
} | |
}() | |
w.Do = <-nextDo | |
w.Do("time no use ptr") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment