-
Notifications
You must be signed in to change notification settings - Fork 0
spawnOn
ffredyk edited this page Jul 23, 2026
·
1 revision
Concurrency
Unary or Binary.
// Unary: spawn on named scheduler
spawnOn ["schedulerName", { code }]
// Binary: with args
<args> spawnOn ["schedulerName", { code }]
Spawns code on a specific named scheduler, rather than the current one. This enables cross-scheduler work distribution — e.g., running AI on a dedicated "AI" scheduler while keeping the "Main" scheduler responsive.
Returns a ScriptHandle owned by the current scheduler.
- Looks up the scheduler by name.
- Creates a new fiber on that scheduler.
- Passes arguments (if binary form) into the fiber.
- Returns a handle visible to the calling scheduler.
The code runs with the target scheduler's budget and fiber management. Suspension (sleep, await) works normally inside the spawned code.
_handle = spawnOn ["AI", {
heavyPathfinding();
sleep 0.1;
heavyPathfinding();
}];[enemyData] spawnOn ["AI", {
params ["_data"];
calculateBehavior(_data);
}];// Main scheduler: UI, input
// "AI" scheduler: pathfinding, behavior
// "Physics" scheduler: collision, movement
for "_i" from 1 to 10 do {
_aiUnits pushBack (spawnOn ["AI", { aiLoop(); }]);
};_handle = spawnOn ["Worker", { longTask(); }];
_result = await (_handle timeout 30);
if (isNil "_result") then {
terminate _handle;
systemChat "Worker task timed out";
};The spawned code runs on a different scheduler — thread safety rules apply. Data shared between schedulers must be frozen, sent via sendTo, or use shared variables.
- spawn — spawn on current scheduler
- currentScheduler — get current scheduler ID
- schedulerName — get scheduler name
- sendTo — transfer data to scheduler
- freeze — make array safe for sharing
- Getting Started
- Language Guide
- Type System
- Control Flow
- Functions & Code
- Strings & Text
- Arrays & Collections
- Concurrency
- Promise System
- Thread Safety
- Host API & Embedding
- CLI Tool
- Bytecode Reference
- Multiplayer
- Syntax Sugar
- Optimization Guide
- Benchmarks
- count
- select
- pushBack
- append
- deleteAt
- deleteRange
- resize
- reverse
- sort
- find
- in
- forEach
- freeze
- thaw
- isFrozen
- currentScheduler
- clientOwner
- allSchedulers
- schedulerName
- schedulerExists
- schedulerBudget
- setSchedulerBudget
- fiberCount
- readyFiberCount
- waitingFiberCount
- schedulerLoad
- sendTo