Пример #1
0
func addDocs() {
	for i, doc := range docs {
		if err := dnf.AddDoc("doc"+strconv.Itoa(i), strconv.Itoa(i), doc); err != nil {
			fmt.Println("add doc[", strconv.Itoa(i), "] error:", err)
			return
		}
	}
}
Пример #2
0
func addDocsRace() {
	task := func(i int, doc string, wg *sync.WaitGroup) {
		if err := dnf.AddDoc("doc"+strconv.Itoa(i), strconv.Itoa(i), doc); err != nil {
			fmt.Println("add doc[", strconv.Itoa(i), "] error:", err)
			panic(err)
		}
		wg.Done()
	}
	var wg sync.WaitGroup
	for i, doc := range docs {
		wg.Add(1)
		go task(i, doc, &wg)
	}
	wg.Wait()
}