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 7:17 PM, 17th November 2026

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

Keyboard shortcuts

j kNext or previous item in a list; scroll elsewhere
g gGo to the top
GGo to the bottom
n pNext or previous page
/Search, where there is a search box
tSwitch between light and dark
g hGo home
g pGo to posts
g bGo to books
g aGo to archives
← →Previous or next image, in the image viewer (z zooms, Esc closes)
?Show this list, even when disabled