Providing futures with a CPU pool and waiting for them

Futures are usually assigned to a Task, which gets assigned to an Executor. When a task is awake, the executor will place the task into a queue, and will call poll() on the task until the process has been completed. Futures offer us a few convenient ways to execute tasks:

  • Spawn a future task manually with futures::executor::block_on().
  • Using futures::executor::LocalPool, which is useful for performing many small tasks on a single thread. In our future returns, we would not be required to implement Send since we are only involving the task on a single thread. However, you are required to use futures::executor::spawn_local() on the Executor if you omit the Send trait.
  • Using futures::executor::ThreadPool, which allows us to offload tasks to other threads.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.234.188