Hacker News new | ask | show | jobs
by eberkund 415 days ago
I created a small library for handling graceful shutdowns in my projects: https://github.com/eberkund/graceful

I find that I typically have a few services that I need to start-up and sometimes they have different mechanisms for start-up and shutdown. Sometimes you need to instantiate an object first, sometimes you have a context you want to cancel, other times you have a "Stop" method to call.

I designed the library to help my consolidate this all in one place with a unified API.

2 comments

Haha, I had the exact same idea, though my API looks a bit less elegant. Maybe it's because it allows the caller to set-up multiple signals to handle and in which way to do it.

https://pkg.go.dev/git.sr.ht/~mariusor/wrapper#example-Regis...

I did something similar as well: https://github.com/pseidemann/finish