Playground / in the browser
Run a process without installing anything.
Curious, but not ready to install anything? Fair enough. A process is one small worker with its own data and its own inbox of messages, and here you can run one. This page has the real Goer in it, built as WebAssembly so it can run in a browser (a few megabytes). Change the program below, press Run, and it’s compiled and run right here in the tab. It starts as the counter from the first tutorial. Run it once, then start breaking it.
What happens when you press Run
The playground looks for one behaviour function: a function that takes the state and a message and returns the new state, like func Handle(s State, m Msg) State. It also needs a matching HandleInit() State for the starting state. If your program has several functions shaped like that, name the one you want run Handle.
Then it does the same thing every time. It sends your process each kind of message your behaviour handles, once each, in the order you declared them, with every field set to zero. After each one it prints what the state looks like now.
If a handler panics, the process crashes, the supervisor starts it again from HandleInit, and you see both the reason and the fresh state. If a handler loops forever, Goer cuts it off after a set amount of work and that shows up as a crash too. A real system does exactly the same.
Things to try: make Tick add two. Panic on something else. Add type Reset struct{ N int } and a case for it. The playground picks up new message types on its own.
What a playground program can’t do
The playground has no outside world to talk to. So anything that needs one is out:
Port("fs") has nothing behind it here, so asking a port for something fails and crashes the process. That’s the honest result: files and networks live outside process code.
After and SelTimeout use the real clock, and the playground reads the state straight after each message. Leave timeouts out of your experiments here.
There’s one node and nobody to connect to, so Remote(...) can’t deliver. Starting local children with Spawn(Worker) works fine.
You can’t import other packages, only goer’s builtins. For anything bigger, goer run on your own machine is the place.