parallelize calls to sendmail
This commit is contained in:
parent
72a148b4a9
commit
9acedd8e4d
18
picolist.go
18
picolist.go
|
@ -13,6 +13,7 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -118,7 +119,7 @@ func recipients(members hashset) ([]bulkRecipients, error) {
|
|||
return splitRecipients(rcpts), nil
|
||||
}
|
||||
|
||||
func sendmail(original *mail.Message, mail string, returnPath string, recps string) error {
|
||||
func sendmail(original *mail.Message, mail string, returnPath string, recps string, errChan chan error, wg *sync.WaitGroup) {
|
||||
if debug {
|
||||
log(original, sendmailPath+" -f "+returnPath+" "+recps+"\n")
|
||||
}
|
||||
|
@ -126,9 +127,9 @@ func sendmail(original *mail.Message, mail string, returnPath string, recps stri
|
|||
cmd.Stdin = strings.NewReader(mail)
|
||||
e := cmd.Run()
|
||||
if e != nil {
|
||||
return err("error on call to sendmail", e)
|
||||
errChan <- err("error on call to sendmail", e)
|
||||
}
|
||||
return nil
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
func forward(mail *mail.Message, returnPath string, members hashset) []error {
|
||||
|
@ -140,8 +141,17 @@ func forward(mail *mail.Message, returnPath string, members hashset) []error {
|
|||
if len(errs) > 0 {
|
||||
return errs
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(rcpts))
|
||||
errChan := make(chan error)
|
||||
for _, bulk := range rcpts {
|
||||
err = sendmail(mail, flatmail, returnPath, bulk.String())
|
||||
go sendmail(mail, flatmail, returnPath, bulk.String(), errChan, &wg)
|
||||
}
|
||||
go func(errChan chan error, wg *sync.WaitGroup) {
|
||||
wg.Wait()
|
||||
close(errChan)
|
||||
}(errChan, &wg)
|
||||
for err := range errChan {
|
||||
errs = appendErr(errs, err)
|
||||
}
|
||||
return errs
|
||||
|
|
Loading…
Reference in New Issue
Block a user