示例#1
0
文件: dnfTestMain.go 项目: hankji/dnf
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
文件: dnfTestMain.go 项目: hankji/dnf
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()
}