Concurrency
Tasks are lightweight and run on the VM’s schedulers, one per logical core by default, so they use several CPU cores and overlap while they wait for I/O or a timer. Their order is not fixed; --schedulers 1 runs one task at a time. The tour page Tasks is a short start.
- Use Task to run work at the same time: start, await, pause and cancel tasks.
- Use a Channel to pass values between tasks. A producer sends and a consumer receives.
- Use an ATS table to share a counter or a cache that tasks update in place.
- Use Cache (
std/cache) to keep computed text that tasks share, within a byte budget. - Use an Actor (
std/actor) for state that one task owns and other tasks reach withcastandcall. - Use a Supervisor (
std/supervisor) to start actors and start again one that crashes.