Module Tethering
NOTE: This page is for planning purposes, but has not been fully implemented within Xita Cross-Compiler yet.
Process Tethers will be added after the firmware system is fully implemented/tested (Current Initiative).
Tether Rules
Module (Process) Tethers are conceptual bonds that allow two concurrently active source modules to communicate. For two (or more) modules to form a tether, they must abide by the following rules:
- 1.) Tethers must be formed between source modules at instant of execution
- 2.) Source Modules can arbitrarily form tethers with Tether Modules
- 3.) Tether Modules cannot form tethers with non-system modules
Forming Tethers
The best practice for forming tethers between modules is to use a Wrapper Function. An example wrapper might look like:
tether Module1 Module2 Module3
This function will trigger Module1-3 to all run simultaneously on separate threads. It will also inform the process scheduler that these three modules should be ran as a tethered Swarm.
The final return value for each module can then be accessed with the tuple operator.
Sending Messages
To send a message to a different module within a swarm, use the following XCSL functionality:
send KEY DATA
Data can be arbitrarily typed; it will be type-checked when the message enters the process scheduler.
See the following example:
send t3xtMe55Ag3 "Hello, Friend!"
Receiving Messages
XCSL implements a complimentary keyword (receive) for catching data from another module's send function. For example, a second module would be able to receive the string sent in the previous message.
print (receive t3xtMe55Ag3)
The receive keyword can determine the data type of a send through use-case context. The XCSL function above would result in the following standard output.
Hello, Friend!
Wrapper Functions
For demonstration purposes, assume Module1, Module2, and Module3 all return integer values.
let wrapper = tether Module1 Module2 Module3
in
wrapper.{0} + wrapper.{1} + wrapper.{2}
In a practical example, each of these integer values might represent their corresponding exit status.
If you assume that 0
represents a successful run for each Module, the wrapper function's sum would:
- Evaluate after each individual module concluded
- Evaluate to 0 if all modules concluded successfully