File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -274,6 +274,38 @@ impl<F: Future> FutureGroup<F> {
274
274
Key ( index)
275
275
}
276
276
277
+ #[ allow( unused) ]
278
+ /// Insert a value into a pinned `FutureGroup`
279
+ ///
280
+ /// This method is private because it serves as an implementation detail for
281
+ /// `ConcurrentStream`. We should never expose this publicly, as the entire
282
+ /// point of this crate is that we abstract the futures poll machinery away
283
+ /// from end-users.
284
+ pub ( crate ) fn insert_pinned ( self : Pin < & mut Self > , future : F ) -> Key
285
+ where
286
+ F : Future ,
287
+ {
288
+ let mut this = self . project ( ) ;
289
+ // SAFETY: inserting a value into the futures slab does not ever move
290
+ // any of the existing values.
291
+ let index = unsafe { this. futures . as_mut ( ) . get_unchecked_mut ( ) } . insert ( future) ;
292
+ this. keys . insert ( index) ;
293
+ let key = Key ( index) ;
294
+
295
+ // If our slab allocated more space we need to
296
+ // update our tracking structures along with it.
297
+ let max_len = this. futures . as_ref ( ) . capacity ( ) . max ( index) ;
298
+ this. wakers . resize ( max_len) ;
299
+ this. states . resize ( max_len) ;
300
+
301
+ // Set the corresponding state
302
+ this. states [ index] . set_pending ( ) ;
303
+ let mut readiness = this. wakers . readiness ( ) ;
304
+ readiness. set_ready ( index) ;
305
+
306
+ key
307
+ }
308
+
277
309
/// Create a stream which also yields the key of each item.
278
310
///
279
311
/// # Example
You can’t perform that action at this time.
0 commit comments