From ab10aa8a6b47b1af5d9fa9b96bdcc5845a65381e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sun, 17 Apr 2022 16:03:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E4=B8=BA=E5=B9=B6=E8=A1=8C?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index c01e7ef..afd2391 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "io/fs" "os" "strings" + "sync" "unicode" "unsafe" @@ -44,12 +45,18 @@ func main() { if err != nil { panic(err) } + defer r.Close() + var wg sync.WaitGroup + wg.Add(len(files)) for i, fn := range files { - fmt.Println("set", "data/"+fn, "=", hex.EncodeToString(helper.StringToBytes(md5s[i]))) - err = r.Set("data/"+fn, md5s[i]) - if err != nil { - panic(err) - } + go func(i int, fn string) { + defer wg.Done() + err = r.Set("data/"+fn, md5s[i]) + fmt.Println("set", "data/"+fn, "=", hex.EncodeToString(helper.StringToBytes(md5s[i]))) + if err != nil { + panic(err) + } + }(i, fn) } - r.Close() + wg.Wait() }