mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
threadpool: spawn new tasks onto a random worker (#683)
* threadpool: submit new tasks to a random worker * Revert unnecessary version bumps
This commit is contained in:
@@ -317,6 +317,16 @@ impl Pool {
|
||||
|
||||
// All workers are active, so pick a random worker and submit the
|
||||
// task to it.
|
||||
self.submit_to_random(task, inner);
|
||||
}
|
||||
|
||||
/// Submit a task to a random worker
|
||||
///
|
||||
/// Called from outside of the scheduler, this function is how new tasks
|
||||
/// enter the system.
|
||||
pub fn submit_to_random(&self, task: Arc<Task>, inner: &Arc<Pool>) {
|
||||
debug_assert_eq!(*self, **inner);
|
||||
|
||||
let len = self.workers.len();
|
||||
let idx = self.rand_usize() % len;
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ impl<'a> tokio_executor::Executor for &'a Sender {
|
||||
// Create a new task for the future
|
||||
let task = Arc::new(Task::new(future));
|
||||
|
||||
self.inner.submit(task, &self.inner);
|
||||
self.inner.submit_to_random(task, &self.inner);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user