Skip to content

Instantly share code, notes, and snippets.

@picatz
Created April 13, 2018 02:52
Show Gist options
  • Save picatz/33938d999472968bf8a61682a500219f to your computer and use it in GitHub Desktop.
Save picatz/33938d999472968bf8a61682a500219f to your computer and use it in GitHub Desktop.
Reverse string example using defer/go routines/wait groups
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