1
1
use std:: {
2
2
marker:: PhantomData ,
3
- sync:: Arc ,
4
3
thread:: { self , ThreadId } ,
5
4
} ;
6
5
@@ -19,17 +18,16 @@ use futures_lite::Future;
19
18
/// let count = Arc::new(AtomicI32::new(0));
20
19
///
21
20
/// // create some owned values that can be moved into another thread
22
- /// let thread_executor_clone = thread_executor.clone();
23
21
/// let count_clone = count.clone();
24
22
///
25
23
/// std::thread::scope(|scope| {
26
24
/// scope.spawn(|| {
27
25
/// // we cannot get the ticker from another thread
28
- /// let not_thread_ticker = thread_executor_clone .ticker();
26
+ /// let not_thread_ticker = thread_executor .ticker();
29
27
/// assert!(not_thread_ticker.is_none());
30
28
///
31
29
/// // but we can spawn tasks from another thread
32
- /// thread_executor_clone .spawn(async move {
30
+ /// thread_executor .spawn(async move {
33
31
/// count_clone.fetch_add(1, Ordering::Relaxed);
34
32
/// }).detach();
35
33
/// });
@@ -43,16 +41,16 @@ use futures_lite::Future;
43
41
/// thread_ticker.try_tick();
44
42
/// assert_eq!(count.load(Ordering::Relaxed), 1);
45
43
/// ```
46
- #[ derive( Debug , Clone ) ]
44
+ #[ derive( Debug ) ]
47
45
pub struct ThreadExecutor < ' a > {
48
- executor : Arc < Executor < ' a > > ,
46
+ executor : Executor < ' a > ,
49
47
thread_id : ThreadId ,
50
48
}
51
49
52
50
impl < ' a > Default for ThreadExecutor < ' a > {
53
51
fn default ( ) -> Self {
54
52
Self {
55
- executor : Arc :: new ( Executor :: new ( ) ) ,
53
+ executor : Executor :: new ( ) ,
56
54
thread_id : thread:: current ( ) . id ( ) ,
57
55
}
58
56
}
@@ -76,7 +74,7 @@ impl<'a> ThreadExecutor<'a> {
76
74
pub fn ticker < ' b > ( & ' b self ) -> Option < ThreadExecutorTicker < ' a , ' b > > {
77
75
if thread:: current ( ) . id ( ) == self . thread_id {
78
76
return Some ( ThreadExecutorTicker {
79
- executor : & * self . executor ,
77
+ executor : & self . executor ,
80
78
_marker : PhantomData :: default ( ) ,
81
79
} ) ;
82
80
}
0 commit comments