Close backends prior to shutdown
We need some way to signal the backends that we are about to shutdown, allowing them to clean up (for example in notmuch committing the db changes). This commit implements a hook which gets called upon shutdown, providing backends implement the io.Closer interface.
This commit is contained in:
parent
d4416e74ac
commit
072b5f453c
1
aerc.go
1
aerc.go
|
@ -178,4 +178,5 @@ func main() {
|
||||||
time.Sleep(16 * time.Millisecond)
|
time.Sleep(16 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
aerc.CloseBackends()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -405,3 +406,21 @@ func (aerc *Aerc) Mailto(addr *url.URL) error {
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (aerc *Aerc) CloseBackends() error {
|
||||||
|
var returnErr error
|
||||||
|
for _, acct := range aerc.accounts {
|
||||||
|
var raw interface{} = acct.worker.Backend
|
||||||
|
c, ok := raw.(io.Closer)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err := c.Close()
|
||||||
|
if err != nil {
|
||||||
|
returnErr = err
|
||||||
|
aerc.logger.Printf("Closing backend failed for %v: %v\n",
|
||||||
|
acct.Name(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnErr
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue