Created
April 13, 2018 02:52
-
-
Save picatz/33938d999472968bf8a61682a500219f to your computer and use it in GitHub Desktop.
Reverse string example using defer/go routines/wait groups
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" | |
import "sync" | |
var wg sync.WaitGroup | |
func reverse(i string) (o string) { | |
for _, v := range i { | |
defer func(r rune) { | |
o += string(r) | |
}(v) | |
} | |
return | |
} | |
func main() { | |
for _ = range make([]int, 10) { | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
fmt.Println(reverse("picat")) | |
}() | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment