Closed astonbitecode closed 5 years ago
Thank you for your question. There are two ways for handling such situation.
Executor
trait provides handle
method. By calling this method, you can create any number of handles that can be sent to separate threads. Since handles implement Spawn
trait, you can spawn futures via a handle without executors.
Running examples that use handles are found in fibers-rs/examples/ directory.
fibers_global
crateThis crate manages the global ThreadPoolExecutor
instead of you, and provides fibers_global::spawn
method that can be called anywhere within your code.
fibers_global
is convenient if you don't need advanced features such as managing multiple executors in a single program.
Thank you for the suggestions. I didn't know about the fibers_global
crate.
I will give it a try, I don't have more complex cases for now.
Hi,
Is it somehow possible for an
Executor
to be shared between threads and also be used for adding new tasks during runtime?I am thinking of something like:
I see that there is the
run_once
, but I suppose that this blocks until all the units that it includes finish. This would make the executor practically unavailable until then I guess.On the other hand, I could just create one new executor whenever I wanted to execute some tasks, but then the occupied threads on the system would increase drastically if there are a lot of tasks to be executed and these tasks are long-lived...