[−][src]Struct please::PleaseHandle
This handle identifies a long-running operation using a unique integer.
Methods
impl<P: ConnectionProvider> PleaseHandle<P>
[src]
impl<P: ConnectionProvider> PleaseHandle<P>
pub fn new(provider: P, title: &str) -> PleaseResult<Self, P::Error>
[src]
pub fn new(provider: P, title: &str) -> PleaseResult<Self, P::Error>
Construct a new handle using the specified connection provider.
The connection provider is typically a connection pool of some kind, or it may be implemented by establishing a new connection each time.
The title is used as a human-readable name to identify this handle. This is useful if you are inspecting the database, or for logging expired handles.
pub fn new_with_cleanup(
provider: P,
title: &str
) -> PleaseResult<Self, P::Error>
[src]
pub fn new_with_cleanup(
provider: P,
title: &str
) -> PleaseResult<Self, P::Error>
Convenience constructor.
Equivalent to calling perform_cleanup
followed by new
.
If you wish to handle expired handles (eg. record them to a log) then
call the methods individually.
pub fn new_with_connection<C: ?Sized>(
provider: P,
title: &str,
conn: &C
) -> QueryResult<Self> where
C: Connection<Backend = Pg>,
[src]
pub fn new_with_connection<C: ?Sized>(
provider: P,
title: &str,
conn: &C
) -> QueryResult<Self> where
C: Connection<Backend = Pg>,
Constructor to use from within an existing transaction.
Allows conditionally creating a handle without losing the atomicity of a single transaction.
pub fn perform_cleanup(provider: &P) -> PleaseResult<Vec<ExpiredId>, P::Error>
[src]
pub fn perform_cleanup(provider: &P) -> PleaseResult<Vec<ExpiredId>, P::Error>
Explicitly clean up old handles. It is recommended to call this before creating a new handle.
This function returns the expired handles (if any) so that you can log them or use them for debugging.
pub fn transaction<R, E, F>(&mut self, f: F) -> Result<R, E> where
E: From<PleaseError<P::Error>>,
F: FnOnce(&P::Connection, i32) -> Result<R, E>,
[src]
pub fn transaction<R, E, F>(&mut self, f: F) -> Result<R, E> where
E: From<PleaseError<P::Error>>,
F: FnOnce(&P::Connection, i32) -> Result<R, E>,
Run a transaction as part of the operation this handle represents.
After beginning the transaction, this method validates that the handle has not expired, whilst also refreshing the expiry and taking a lock on the row, to prevent it being expired by another thread whilst this transaction is in progress.
The callback is passed two arguments: a reference to the connection, and the integer ID of this handle. Currently this is the only way to access the handle's ID as it is not recommended to use this ID outside of a transaction.
pub fn refresh(&mut self) -> PleaseResult<(), P::Error>
[src]
pub fn refresh(&mut self) -> PleaseResult<(), P::Error>
Refreshes the handle, resetting the time before it will be automatically closed.
This is equivalent to running an empty transaction.
pub fn expire(&mut self) -> PleaseResult<ExpiredId, P::Error>
[src]
pub fn expire(&mut self) -> PleaseResult<ExpiredId, P::Error>
Expire the handle. Future operations on this handle will fail with the error Expired
.
Useful for testing.
pub fn close(self) -> PleaseResult<(), P::Error>
[src]
pub fn close(self) -> PleaseResult<(), P::Error>
Close the handle, allowing any errors to be handled.
This is automatically called when a handle is dropped, but in that case errors are silently ignored.
pub fn id(&self) -> i32
[src]
pub fn id(&self) -> i32
Get the ID of this handle.
A good rule of thumb is to never use this outside of a transaction, as in that case it may not have been recently validated.
Trait Implementations
impl<P: Debug + ConnectionProvider> Debug for PleaseHandle<P>
[src]
impl<P: Debug + ConnectionProvider> Debug for PleaseHandle<P>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<P: ConnectionProvider> Drop for PleaseHandle<P>
[src]
impl<P: ConnectionProvider> Drop for PleaseHandle<P>
Auto Trait Implementations
impl<P> Send for PleaseHandle<P> where
P: Send,
impl<P> Send for PleaseHandle<P> where
P: Send,
impl<P> Sync for PleaseHandle<P> where
P: Sync,
impl<P> Sync for PleaseHandle<P> where
P: Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
ⓘImportant traits for &'a mut Rfn borrow(&self) -> &T
[src]
fn borrow(&self) -> &T
Immutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
ⓘImportant traits for &'a mut Rfn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> IntoSql for T
impl<T> IntoSql for T
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
Convert self
to an expression for Diesel's query builder. Read more
ⓘImportant traits for &'a mut Rfn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel's query builder. Read more