-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from SrTobi-Forks/tobias/relax-atomic-ref
relax lifetime constraints on AtomicRef
- Loading branch information
Showing
3 changed files
with
39 additions
and
4 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
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,34 @@ | ||
use std::future::Future; | ||
|
||
use atomic_refcell::AtomicRefCell; | ||
|
||
fn spawn<Fut>(_future: Fut) | ||
where | ||
Fut: Future<Output = ()> + Send + Sync, | ||
{ | ||
} | ||
|
||
async fn something_async() {} | ||
|
||
// see https://github.com/bholley/atomic_refcell/issues/24 | ||
#[test] | ||
fn test_atomic_ref_in_spawn() { | ||
let arc: Box<dyn Fn() -> usize + Send + Sync> = Box::new(|| 42); | ||
let a = AtomicRefCell::new(arc); | ||
spawn(async move { | ||
let x = a.borrow(); | ||
something_async().await; | ||
assert_eq!(x(), 42); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn test_atomic_ref_mut_in_spawn() { | ||
let arc: Box<dyn Fn() -> usize + Send + Sync> = Box::new(|| 42); | ||
let a = AtomicRefCell::new(arc); | ||
spawn(async move { | ||
let x = a.borrow_mut(); | ||
something_async().await; | ||
assert_eq!(x(), 42); | ||
}); | ||
} |