From fba8b2af286ace2aa857123e9c14aa794a42f830 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 2 Feb 2016 18:11:51 +0100 Subject: Go concurrent --- authorize.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'authorize.go') diff --git a/authorize.go b/authorize.go index 0dc82a2..6b3d22e 100644 --- a/authorize.go +++ b/authorize.go @@ -1,6 +1,9 @@ package acme -import "time" +import ( + "sync" + "time" +) // Authorization request type Authorization struct { @@ -61,19 +64,27 @@ func (p *Provider) authz(s Signer, domain string, sol map[ChalType]Solver) error return err } // second step: choose and start solver + wg := sync.WaitGroup{} for _, ch := range req.Supported(sol) { - if err = p.solve(s, ch, sol[ch.Type]); err != nil { - return err - } + wg.Add(1) + go func(ch Challenge) { + p.solve(s, ch, sol[ch.Type]) + wg.Done() + }(ch) } + wg.Wait() return nil } func (p *Provider) Authorize(s Signer, d *Desire) error { + wg := sync.WaitGroup{} for _, domain := range d.altnames { - if err := p.authz(s, domain, d.solver); err != nil { - return err - } + wg.Add(1) + go func(domain string) { + p.authz(s, domain, d.solver) + wg.Done() + }(domain) } + wg.Wait() return nil } -- cgit v1.2.3