Open NuSkooler opened 10 months ago
Hi @NuSkooler 👋
That's because WMI needs to be initialized per-thread, so any future that uses the connection cannot move between threads (aka, the resulting futures are !Send
).
async_trait
supports this, so using #[async_trait(?Send)]
should fix this.
Let me know if this helps!
@ohadravid Thanks, that makes sense. This does leave me in a dilemma, though it's likely my being fairly new to Rust: Removing Send trickles throughout the code meaning I can from my understanding, no longer use this method in other async/tokio code.
Is there a work around?
The work around I'm using right now is hoisting the work to non-async code that's wrapped with Tokio spawn_blocking
, which doesn't feel that great.
Maybe something like https://github.com/ohadravid/wmi-rs/issues/55#issuecomment-1214223034 can help in your case?
@ohadravid That looks great, I'll check it out. Thanks!
I'm able to use
async_query()
in simple tests, but not within an async trait. A simple example:Results in the following:
Any ideas? Note that the same code works outside of a trait method.