Feature/not send futures #72
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sendfree futures/Async (single-threaded executors)Concurrency and async programming do not require a multi-threaded environment. You can run async tasks on a single-threaded executor, which allows you to write async code without the Send bound.
This approach has several benefits:
Simpler code: No need for Arc, Mutex(RwLock), or other thread synchronization primitives for shared state.
Ergonomic references: You can freely use references within your async code without worrying about moving data across threads. 🤯
Efficient design: This model aligns with the “Thread-per-Core” pattern, letting you safely run multiple async tasks concurrently on a single thread.
In short: you get all the power of async/await without the complexity of multi-threaded synchronization all the time.
Just switching to a LocalExecutor or something like Tokio LocalSet should be enough.
If you want to enable single-threaded, Send-free async support, you can enable the optional feature
not-send-futureswhen adding fmodel-rust to your project:Enabling this feature allows your application and infrastructure code to use single-threaded async without requiring Send bounds or thread-synchronization primitives like Arc and Mutex/RwLock. This makes writing async code simpler and more ergonomic in single-threaded environments. by utilizing cheaper primitives like Rc and RefCell.
Example of the concurrent execution of the aggregate in single-threaded environment (behind feature -
SendfreeFutures):