Skip to content

Commit

Permalink
revert function deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
conradludgate committed May 18, 2024
1 parent 2be8ce6 commit 00601b9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/future/future_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,38 @@ impl<F: Future> FutureGroup<F> {
Key(index)
}

#[allow(unused)]
/// Insert a value into a pinned `FutureGroup`
///
/// This method is private because it serves as an implementation detail for
/// `ConcurrentStream`. We should never expose this publicly, as the entire
/// point of this crate is that we abstract the futures poll machinery away
/// from end-users.
pub(crate) fn insert_pinned(self: Pin<&mut Self>, future: F) -> Key
where
F: Future,
{
let mut this = self.project();
// SAFETY: inserting a value into the futures slab does not ever move
// any of the existing values.
let index = unsafe { this.futures.as_mut().get_unchecked_mut() }.insert(future);
this.keys.insert(index);
let key = Key(index);

// If our slab allocated more space we need to
// update our tracking structures along with it.
let max_len = this.futures.as_ref().capacity().max(index);
this.wakers.resize(max_len);
this.states.resize(max_len);

// Set the corresponding state
this.states[index].set_pending();
let mut readiness = this.wakers.readiness();
readiness.set_ready(index);

key
}

/// Create a stream which also yields the key of each item.
///
/// # Example
Expand Down

0 comments on commit 00601b9

Please sign in to comment.