Learn
Concurrency
Use every core with Spawn and Parallel For, wait without blocking with Async and Await, and share data safely between threads.
FutureBlitz has a tool for each kind of concurrency. Spawn and Parallel For run heavy work on
every core. Async and Await wait for files, networks, and time without blocking, on the main
thread, where coroutines are written as the steps they take. Channels, Atomics, Mutexes, and
Shared Classes share data between threads, and the compiler checks every value that crosses one,
so a data race is a compile error rather than a bug to hunt for.
Tutorials
- Spawn and Task Run work on other cores with Spawn, wait for its result with a Task, and give long-running work a Thread of its own.
- Parallel For Split a loop's passes over every core with Parallel For, and keep each pass to its own element.
- Channels Pass values between threads in order with a Channel, close it when the sender is done, and check it without waiting.
- Mutex and Atomic Share counters between threads with Atomic, and larger data with a Mutex and Lock.
- Sendable and Shared Class Know which values can cross threads, and make a Class whose objects every thread can share.
- Async and Await Write code that waits for files and other work without blocking, with Async Functions, Await, and the errors their Tasks carry.
- Coroutines and Schedulers Write sequences that take time as Async Functions that Await Wait, and run them on a Scheduler you tick yourself.
- The main thread Keep main-thread code on the main thread with @MainThread, and run coroutines from a loop of your own with Scheduler.Main.Step.
The rules behind this area are in the language reference.
Report an issue with this page or with FutureBlitz on GitHub.