Created
August 9, 2022 10:54
-
-
Save Reine0017/ad50a871ce5dae1865fc300583619a11 to your computer and use it in GitHub Desktop.
complex channel
This file contains 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" | |
"strings" | |
) | |
type FullName struct { | |
firstName string | |
lastName string | |
} | |
func NameFunc(nameChannel chan FullName, name string) { | |
splitName := strings.Split(name, " ") | |
res := FullName{} | |
res.firstName = "firstName: " + splitName[0] | |
res.lastName = "lastName: " + splitName[1] | |
nameChannel <- res | |
} | |
func main() { | |
nameChannel := make(chan FullName) | |
go NameFunc(nameChannel, "Reine Fang") | |
value := <-nameChannel //blocking call | |
fmt.Println("Full Name", value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment