<aside>
❗ IMPORTENT: The Chan must ALWAYS return something, if err != nil
is checked for and an error is returned in the if
, nil must be returned in the case of no error, since the program will wait indefinitely for an answer.
</aside>
errChan := make(chan error)
go func() {
err := incrementNumberOfSentEmails()
if err != nil {
**errChan <- err**
return
}
**errChan <- nil**
}()
err = <-errChan // here it would break off, as it is waiting for an answer
if err != nil {
return err
}