diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-01-05 14:41:25 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-01-05 16:11:15 +0100 |
commit | c486127b30964009047274139f63c590abf1a0b6 (patch) | |
tree | 090ff09d55573e3e11a9f321ca4a24643e0af263 | |
parent | 0d7866d93a4aaf115b0e47c0c06c1ac2c9600776 (diff) |
Add helper function to do something with db and easily return the result
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | lib/domain/libimagmail/src/notmuch/connection.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/domain/libimagmail/src/notmuch/connection.rs b/lib/domain/libimagmail/src/notmuch/connection.rs index 22bfd2b4..914835a3 100644 --- a/lib/domain/libimagmail/src/notmuch/connection.rs +++ b/lib/domain/libimagmail/src/notmuch/connection.rs @@ -74,4 +74,19 @@ impl NotmuchConnection { }) } + pub(crate) fn process<F, T>(&self, f: F) -> Result<T> + where F: FnOnce(&Database) -> Result<T> + { + self.db + .lock() + .map_err(|_| ErrorMsg::LockError) + .map_err(Error::from) + .and_then(|lock| { + lock.begin_atomic()?; + let r = f(&lock); + lock.end_atomic()?; + r + }) + } + } |