Commit ea6d876 1 parent 1344092 commit ea6d876 Copy full SHA for ea6d876
File tree 1 file changed +38
-1
lines changed
1 file changed +38
-1
lines changed Original file line number Diff line number Diff line change 1
1
use std:: { future:: Future , io} ;
2
2
3
3
use monoio:: BufResult ;
4
- use reusable_box_future:: ReusableLocalBoxFuture ;
4
+ use reusable_box_future:: { ReusableLocalBoxFuture , ReusableBoxFuture } ;
5
5
6
6
use crate :: buf:: { Buf , RawBuf } ;
7
7
@@ -83,3 +83,40 @@ impl Default for MaybeArmedBoxFuture<io::Result<()>> {
83
83
}
84
84
}
85
85
}
86
+
87
+ #[ derive( Debug ) ]
88
+ pub struct SendableMaybeArmedBoxFuture < T > {
89
+ slot : ReusableBoxFuture < T > ,
90
+ armed : bool ,
91
+ }
92
+
93
+ impl < T > SendableMaybeArmedBoxFuture < T > {
94
+ pub fn armed ( & self ) -> bool {
95
+ self . armed
96
+ }
97
+ pub fn arm_future < F > ( & mut self , f : F )
98
+ where
99
+ F : Future < Output = T > + ' static + Send ,
100
+ {
101
+ self . armed = true ;
102
+ self . slot . set ( f) ;
103
+ }
104
+ pub fn poll ( & mut self , cx : & mut std:: task:: Context < ' _ > ) -> std:: task:: Poll < T > {
105
+ match self . slot . poll ( cx) {
106
+ r @ std:: task:: Poll :: Ready ( _) => {
107
+ self . armed = false ;
108
+ r
109
+ }
110
+ p => p,
111
+ }
112
+ }
113
+ pub fn new < F > ( f : F ) -> Self
114
+ where
115
+ F : Future < Output = T > + ' static + Send ,
116
+ {
117
+ Self {
118
+ slot : ReusableBoxFuture :: new ( f) ,
119
+ armed : false ,
120
+ }
121
+ }
122
+ }
You can’t perform that action at this time.
0 commit comments