Goroutine快速入门

package main

import (
	"fmt"
	"strconv"
	"time"
)

func test() {
	for i := 1; i <= 10; i++ {
		fmt.Println("test hello world, "+strconv.Itoa(i))
		time.Sleep(1)
	}
}
func main() {
	// 开启一个协程
	go test()
	for i := 1; i <= 10; i++ {
		fmt.Println("main hello golang "+strconv.Itoa(i))
		time.Sleep(1)
	}
}

猜你喜欢

转载自blog.csdn.net/qq2942713658/article/details/113408121