smol-rs / async-executor

Async executor
Apache License 2.0
334 stars 45 forks source link

StaticLocalExecutor usage example? #119

Open jbr opened 5 months ago

jbr commented 5 months ago

I was excited to see the addition of StaticExecutor and StaticLocalExecutor optimizations, and started async-global-executor#17 with the intent to adopt both of them. However, it is unclear from the examples how exactly to use StaticLocalExecutor.

The documentation suggests using it with thread_local!, but LocalKey intentionally only offers scoped lifetime access in with in order to prevent usage from other threads. StaticLocalExecutor::spawn requires &'static self, which cannot be directly obtained from tls. Does that lifetime have to be 'static? If so, how is this intended to be used?

Thanks!