Prevent Go Programs from Exiting

Show QR code Hide QR code
QR code linking to https://navendu.me/tils/24-8-24-prevent-go-programs-from-exiting/

You can use channels to prevent Go programs from exiting.

I have found this to be useful when running Go + Wasm on the browser where I run into errors like:

wasm_exec.js:378 Uncaught Error: bad callback: Go program has already exited

This can be prevented by wrapping your code with a channel:

c := make(chan bool) // creates a new channel
// your code goes here
<-c // perpetually waits for the channel to receive data

Webmentions • Last updated at 10:43 AM, 23rd December 2025

Have you written a response to this? Send me a webmention by entering the URL.