See REFERENCE.md for the complete language reference.
spawn is a language builtin (like make, append). No import required. Patched into Go's type universe via build/patch-gotypes.go.
done := spawn(funcName, arg1, arg2, ...)
done := spawn("local", funcName, arg1, arg2, ...) // explicit transport
Creates a new domain — an isolated OS process (native) or Worker (JS) — running funcName(arg1, arg2, ...) with its own cooperative scheduler and heap. Returns chan struct{} (lifecycle channel).
All data arguments and channel element types must implement moxie.Codec:
import "moxie"
type Codec interface {
EncodeTo(w io.Writer) error
DecodeFrom(r io.Reader) error
}
Built-in codec types encode little-endian by default. Big-endian aliases exist for protocols like Bitcoin:
| Default (LE) | Big-endian (BE) | Size |
|---|---|---|
moxie.Bool, moxie.Int8, moxie.Uint8 | — | 1 byte |
moxie.Int16, moxie.Uint16 | moxie.BigInt16, moxie.BigUint16 | 2 bytes |
moxie.Int32, moxie.Uint32 | moxie.BigInt32, moxie.BigUint32 | 4 bytes |
moxie.Int64, moxie.Uint64 | moxie.BigInt64, moxie.BigUint64 | 8 bytes |
moxie.Float32 | moxie.BigFloat32 | 4 bytes |
moxie.Float64 | moxie.BigFloat64 | 8 bytes |
moxie.Bytes | — | 4-byte LE length prefix + data |
User-defined structs implement Codec by defining EncodeTo/DecodeFrom methods that encode each field.
import "moxie"
func worker(n moxie.Int32, scale moxie.Float64) {
println(float64(n) * float64(scale))
}
func main() {
spawn(worker, moxie.Int32(42), moxie.Float64(2.5))
}
The type checker (patched go/types) validates:
chan struct{}The compiler's SSA validator additionally enforces:
moxie.Codecmoxie.Codecinterface{} values cross the boundaryNon-constant, non-channel values passed to spawn cannot be used afterward:
x := compute()
spawn(worker, x)
println(x) // compile error: ownership moved to child
socketpair() + fork(). Child gets COW copy of parent memory. Each domain has its own Boehm GC heap, run queue, and goroutine stacks.
$rt.domain.spawn(async () => fn(args)). Slices spread-copied, maps Object.assign'd. Isolated microtask scheduler per domain.