Supervised fire-and-forget in Go 0 ▲ Redowan's Reflections 2 hours ago · 9 min read1732 words · Tech · hide · 0 comments These days, unmanaged go func() calls don’t appear as often as they used to in the early days of Go. At this point, everyone knows Dave Cheney’s maxim to “never start a goroutine without knowing how it will stop”. Even so, I still occasionally run into unsynchronized go func() calls doing fire-and-forget work. I’m not talking about jobs handed to a dedicated task queue such as Asynq. In that case, the task system owns the lifecycle of the tasks it starts. I mean smaller, best-effort jobs where it’s super tempting to start a task with go func() and just forget about it. Sending a notification or writing an expensive diagnostic log often falls into this category. It typically looks like this: func (h *handler) createOrder(w http.ResponseWriter, r *http.Request) { user := r.URL.Query().Get("user") ctx := r.Context() go func() { h.tasks.SendNotification(ctx, user) // (1) }() go func() { h.tasks.WriteDiagnosticLog(ctx, user) // (2) }() w.WriteHeader(http.StatusAccepted) } In the handler… No comments yet. Log in to reply on the Fediverse. Comments will appear here.