func main() {
var wg sync.WaitGroup
wg.Add(1)
go func() {
fmt.Println("1")
wg.Done()
}()
wg.Wait()
wg.Add(1)
go func() {
fmt.Println("2")
wg.Done()
}()
wg.Wait()
wg.Add(1)
go func() {
fmt.Println("3")
wg.Done()
}()
wg.Wait()
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
fmt.Println("1")
wg.Done()
}()
wg.Wait()
wg.Add(1)
go func() {
fmt.Println("2")
wg.Done()
}()
wg.Wait()
wg.Add(1)
go func() {
fmt.Println("3")
wg.Done()
}()
wg.Wait()
}
2019-09-02
ype Cat struct {
name string
age int
location string
}
func (Cat *Cat) Grow() {
}
func (Cat *Cat) Move(string) string {
return "Hello World"
}
name string
age int
location string
}
func (Cat *Cat) Grow() {
}
func (Cat *Cat) Move(string) string {
return "Hello World"
}
2019-08-30
func main() {
var wg sync.WaitGroup
wg.Add(3)
go func() {
fmt.Println("1")
wg.Done()
}()
go func() {
time.Sleep(100 * time.Millisecond)
fmt.Println("2")
wg.Done()
}()
go func() {
time.Sleep(200 * time.Millisecond)
fmt.Println("3")
wg.Done()
}()
wg.Wait()
}
var wg sync.WaitGroup
wg.Add(3)
go func() {
fmt.Println("1")
wg.Done()
}()
go func() {
time.Sleep(100 * time.Millisecond)
fmt.Println("2")
wg.Done()
}()
go func() {
time.Sleep(200 * time.Millisecond)
fmt.Println("3")
wg.Done()
}()
wg.Wait()
}
2019-08-30
func main() {
for i := 0; i < 10; i++ {
defer fmt.Printf("%d ", func(i int) int{
fmt.Printf("%d ", fibonacci(i))
return fibonacci(i)
}(i))
}
}
for i := 0; i < 10; i++ {
defer fmt.Printf("%d ", func(i int) int{
fmt.Printf("%d ", fibonacci(i))
return fibonacci(i)
}(i))
}
}
2019-08-29
length := (2)
capacity := (4)
length = (7)
e2 := (0)
e3 := (8)
e4 := (11)
capacity := (4)
length = (7)
e2 := (0)
e3 := (8)
e4 := (11)
2019-08-27
最简单的方法:
package main
import (
"fmt"
"time"
)
func main() {
go func() {
fmt.Println("1")
}()
time.Sleep(100 * time.Millisecond)
go func() {
fmt.Println("2")
}()
time.Sleep(100 * time.Millisecond)
go func() {
fmt.Println("3")
}()
time.Sleep(100 * time.Millisecond)
}
package main
import (
"fmt"
"time"
)
func main() {
go func() {
fmt.Println("1")
}()
time.Sleep(100 * time.Millisecond)
go func() {
fmt.Println("2")
}()
time.Sleep(100 * time.Millisecond)
go func() {
fmt.Println("3")
}()
time.Sleep(100 * time.Millisecond)
}
2019-07-26
package main
import "fmt"
func main() {
ch2 := make(chan string, 1)
go func() {
ch2 <- ("已到达!")
}()
var value string = "数据"
value = value + (<- ch2)
fmt.Println(value)
}
import "fmt"
func main() {
ch2 := make(chan string, 1)
go func() {
ch2 <- ("已到达!")
}()
var value string = "数据"
value = value + (<- ch2)
fmt.Println(value)
}
2019-07-19