pub struct WriteTransaction<'a, F: Flash + 'a, M: RawMutex + 'a> { /* private fields */ }
Expand description
In-progress write transaction.
§Cancelation
If any operation within the transaction (write
or delete
) either fails, or is canceled (due
to dropping its Future
before completion), the entire write transaction is canceled.
When the transaction is canceled, all operations will return TransactionCanceled
errors.
To recover, you must drop the entire WriteTransaction
, and (if desired) open a new one to retry
the writes.
Implementations§
Source§impl<'a, F: Flash + 'a, M: RawMutex + 'a> WriteTransaction<'a, F, M>
impl<'a, F: Flash + 'a, M: RawMutex + 'a> WriteTransaction<'a, F, M>
Sourcepub async fn write(
&mut self,
key: &[u8],
value: &[u8],
) -> Result<(), WriteError<F::Error>>
pub async fn write( &mut self, key: &[u8], value: &[u8], ) -> Result<(), WriteError<F::Error>>
Write a key to the database.
If the key was already present, the previous value is overwritten.
Sourcepub async fn delete(&mut self, key: &[u8]) -> Result<(), WriteError<F::Error>>
pub async fn delete(&mut self, key: &[u8]) -> Result<(), WriteError<F::Error>>
Delete a key from the database.
If the key was not present, this is a no-op.
Sourcepub async fn commit(self) -> Result<(), CommitError<F::Error>>
pub async fn commit(self) -> Result<(), CommitError<F::Error>>
Commit the transaction.
This will wait until no read transaction is open. While waiting, opening new read transactions is blocked, to prevent readers from starving writers.
This makes all the writes permanent on the underlyling database. When it returns, the writes are guaranteed to be fully safely written to flash, so they can’t get lost by a crash or a power failure anymore.
Committing is atomic: if commit is interrupted (due to power loss, crash, or canceling the future), it is guaranteed that either all or none of the writes in the transaction are committed.