Skip to content

Commit

Permalink
Prepend method
Browse files Browse the repository at this point in the history
  • Loading branch information
benbromhead committed Jan 12, 2021
1 parent 1661bad commit ba30579
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions futures-util/src/stream/futures_ordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ impl<Fut: Future> FuturesOrdered<Fut> {
self.next_incoming_index += 1;
self.in_progress_queue.push(wrapped);
}

/// Prepends a future to the front of the queue.
///
/// This function submits the given future to the internal set for managing.
/// This function will not call `poll` on the submitted future. The caller
/// must ensure that `FuturesOrdered::poll` is called in order to receive
/// task notifications. This future will be the next future to be returned
/// complete.
pub fn prepend(&mut self, future: Fut) {
let wrapped = OrderWrapper {
data: future,
index: self.next_outgoing_index - 1,
};
self.next_outgoing_index -= 1;
self.in_progress_queue.push(wrapped);
}
}

impl<Fut: Future> Default for FuturesOrdered<Fut> {
Expand Down

0 comments on commit ba30579

Please sign in to comment.