-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dropper): fix issue with atomic & weak refs
Signed-off-by: vados <[email protected]>
- Loading branch information
Showing
5 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ proc-macro2 = "1.0.69" | |
quote = "1.0.33" | ||
syn = "2.0.38" | ||
tokio = "1.33.0" | ||
uuid = "1.10.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::sync::atomic::AtomicBool; | ||
use std::sync::Weak; | ||
|
||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use uuid::Uuid; | ||
|
||
use async_dropper::{AsyncDrop, AsyncDropError}; | ||
|
||
/// Ensure that async-dropper works with atomic structures and weak refs | ||
/// | ||
/// see: https://github.com/t3hmrman/async-dropper/issues/21 | ||
#[tokio::test] | ||
async fn gh_issue_21() -> Result<()> { | ||
#[derive(Default)] | ||
pub struct State(String); | ||
|
||
#[derive(Default, PartialEq, Eq, AsyncDrop)] | ||
pub struct Supervisor { | ||
pub socket_bot_id: Uuid, | ||
pub room_id: String, | ||
pub private_room: AtomicBool, | ||
pub state: Weak<State>, | ||
} | ||
|
||
#[async_trait] | ||
impl AsyncDrop for Supervisor { | ||
async fn async_drop(&mut self) -> Result<(), AsyncDropError> { | ||
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await; | ||
Ok(()) | ||
} | ||
} | ||
|
||
let mut supervisor = Supervisor::default(); | ||
supervisor.room_id = "test".into(); | ||
|
||
drop(supervisor); | ||
|
||
Ok(()) | ||
} |