These are the examples used in the blog post
- Basic Example that i used in the blog post as a base and improved it step by step.
- Example with Done Channel and WaitGroup with Force Quit
- Example with Timeouts
- Example with context.Context instead of Done Channel
- Example with errgroup.Group instead of WaitGroups
Creates a simples http.Server with:
/long-running-job
that sleeps for 10 seconds to demonstrate all active connections will finish before termination./hello
that will writehi
back :).
$ go run examples/lib/http_example/main.go
You now have a HTTP server that has to endpoints:
/hello
which simply writeshi
back.log-runing-job
which is simpletime.Sleep
and then writesdone
back.
Now when you send a HTTP request to /log-running-job
, and press ctrl+c
in server, the code will wait for all requests to finish and then terminates.