I have found these related issues/pull requests
Description
The current implementation of the smol runtime is calling smol::spawn(), which is a fancy global variable. However, consumers of the crate may want to create their own executor to fix some problems with this api:
- Number of threads are set at runtime, and not at compile time by the developer that knows better.
- Requires an environment variable for the number of threads
- the global executor is hidden and cannot be accessed directly
Allowing to set your own executor would be better as you could personalize it to your desires
Prefered solution
One way i'd fix it is:
- create a
static SMOL_EXECUTOR: Arc<Mutex<Option<Executor<'_>>>>
- create a
fn set_smol_executor() function to allow setting the executor without dealing with the mutex
- Replace smol::spawn by something like this:
if let Some(exec) = SMOL_EXECUTOR.lock() {
exec.spawn(fut)
else {
smol::spawn(fut)
}
I am willing to implement it if greenlit
Is this a breaking change? Why or why not?
We're only adding here :)
I have found these related issues/pull requests
Description
The current implementation of the smol runtime is calling smol::spawn(), which is a fancy global variable. However, consumers of the crate may want to create their own executor to fix some problems with this api:
Allowing to set your own executor would be better as you could personalize it to your desires
Prefered solution
One way i'd fix it is:
static SMOL_EXECUTOR: Arc<Mutex<Option<Executor<'_>>>>fn set_smol_executor()function to allow setting the executor without dealing with the mutexI am willing to implement it if greenlit
Is this a breaking change? Why or why not?
We're only adding here :)