pub struct BulkControl { /* private fields */ }Expand description
Cancellation and progress for the four chunked bulk paths (0.13.8, W7.6, D-181).
Default is “neither”, which is what Database::bulk_import and its three
siblings pass. The _with variants take one of these:
let token = CancelToken::new();
let stopper = token.clone();
tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
stopper.cancel();
});
let control = BulkControl::new()
.cancel_with(token)
.on_progress(|p| println!("{}/{} rows", p.written, p.total));
match db.bulk_import_with(edges, control).await {
Ok(n) => println!("imported {n}"),
Err(e) => println!("stopped after {}: {}", e.written, e.cause),
}The callback runs on the importing task, between chunks. It is therefore
on the critical path: whatever it does is time the next chunk is not being
sent in. Printing or updating a counter is what it is for; a blocking write
is not, and neither is anything that calls back into the same Database,
which would deadlock the loop against a channel it is itself draining.
Implementations§
Source§impl BulkControl
impl BulkControl
Sourcepub fn cancel_with(self, token: CancelToken) -> Self
pub fn cancel_with(self, token: CancelToken) -> Self
Stop at the next chunk boundary when token is cancelled.
Sourcepub fn on_progress(
self,
f: impl Fn(BulkProgress) + Send + Sync + 'static,
) -> Self
pub fn on_progress( self, f: impl Fn(BulkProgress) + Send + Sync + 'static, ) -> Self
Call f after every chunk commits. See the note on BulkControl
about what this closure is allowed to do.
Trait Implementations§
Source§impl Clone for BulkControl
impl Clone for BulkControl
Source§fn clone(&self) -> BulkControl
fn clone(&self) -> BulkControl
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BulkControl
impl Debug for BulkControl
Source§impl Default for BulkControl
impl Default for BulkControl
Source§fn default() -> BulkControl
fn default() -> BulkControl
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for BulkControl
impl !UnwindSafe for BulkControl
impl Freeze for BulkControl
impl Send for BulkControl
impl Sync for BulkControl
impl Unpin for BulkControl
impl UnsafeUnpin for BulkControl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request