1
0
mirror of https://github.com/actix/examples synced 2025-01-22 14:05:55 +01:00

15 lines
673 B
Markdown
Raw Normal View History

2022-10-16 19:24:17 +01:00
# Async Data Factory
2022-03-06 00:43:10 +00:00
2022-10-16 19:24:17 +01:00
This is an example demonstrating the construction of async state with `App::data_factory`.
2020-06-22 21:16:25 +08:00
## Reason:
2022-03-06 00:43:10 +00:00
Use of a `data_factory` would make sense in these situations:
2022-03-06 00:43:10 +00:00
- When async state does not necessarily have to be shared between workers/threads.
2022-10-16 19:24:17 +01:00
- When an async state would spawn tasks. If state was centralized there could be a possibility the tasks get an unbalanced distribution on the workers/threads.
2020-06-22 21:16:25 +08:00
2022-10-16 19:24:17 +01:00
## Context
2020-06-22 21:16:25 +08:00
2022-10-16 19:24:17 +01:00
The real world difference can be vary by the work you are doing but in general it's a good idea to spread your similarly-expensive async tasks evenly between threads and have as little cross threads synchronization as possible.