Skip to content

Commit

Permalink
feat(jstzd): implement async-drop for container
Browse files Browse the repository at this point in the history
  • Loading branch information
ryutamago committed Sep 23, 2024
1 parent 2d524e8 commit 2f1f863
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions crates/jstzd/src/docker/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@ use bollard::Docker;
use log::error;
use std::sync::Arc;

#[derive(Default)]
pub struct Container {
pub id: String,
client: Option<Arc<Docker>>,
dropped: bool,
_private: (),
}

impl Default for Container {
fn default() -> Self {
Self {
id: String::new(),
client: None,
dropped: false,
_private: (),
}
}
}

impl Container {
/// Creates a new container with running `id`
pub(super) fn new(client: Arc<Docker>, id: String) -> Self {
Expand Down Expand Up @@ -81,14 +71,10 @@ impl AsyncDrop for Container {
}

impl Drop for Container {
// same drop implementation as in async-dropper-simple crate
// https://github.com/t3hmrman/async-dropper/blob/ec6e5bbd6c894b23538cfec80375bcaefb8e5710/crates/async-dropper-simple/src/no_default_bound.rs#L111
fn drop(&mut self) {
if !self.dropped {
// Prevent the copy `this` to drop again
self.dropped = true;
let mut this = std::mem::take(self);
// Prevent the original `self` to drop again
self.dropped = true;
TokioScope::scope_and_block(|s| {
s.spawn(async move {
Expand Down

0 comments on commit 2f1f863

Please sign in to comment.