Hacker News new | past | comments | ask | show | jobs | submit login

> 2. I am using a normal thread but when I make it async the compiler wants Send.

This is likely because you are using the multi-threaded scheduler, which requires futures to be Send, even if you’re running only a single thread. This is because Tokio is based on a “work stealing” runtime, so in “normal” operations, expects the futures themselves to be able to be shuffled around threads where necessary.

For you use case, try running the single threaded executor, additionally try the “local set” executors. These do not require Send as they are statically guaranteed to be confined to the thread they are spawned on. Block on will also work.

Out of curiosity though, how is the interaction with Rhai performed, are you passing around the engine, and executing the code at certain points where applicable? Do you just need certain results from it sometimes? Etc?




Right, GPT-4 explained that much about shuffling. I am trying to do all the interaction with MPSC channels but was still running into issues.

I think I have a lot of good advice to go try now. Thanks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: