The point
samber/do provides Shutdownable interface so we can drop connections, stop background tasks... to achieve a graceful shutdown.
I think it would be good if samber/do also supports Startupable interface like:
type Startupable interface {
Startup(context.Context) error
}
The mechanism of Startupable could be similar to the OnStart hook in uber/fx.
This would provide a clear place to build connections, start background tasks, and fetch initial data.
Startupable vs. do startup in constructor
#92 suggests doing startup work inside constructors by passing a context.Context.
Having a separate Startup function could be preferable in some cases:
- Some projects already use a
NewXxx → Startup → Shutdown template (which in our view makes the code cleaner, as the constructor only handles injections while Startup handles initializations).
- Migration from uber/fx to samber/do could be easier.
That said, #92 (the InvokeContext idea) is not in conflict with Startupable. In some cases, we might still want to perform I/O operations during construction, depending on how we understand the business logic and layer the code.
It could be beneficial if samber/do supported both approaches.
The point
samber/do provides
Shutdownableinterface so we can drop connections, stop background tasks... to achieve a graceful shutdown.I think it would be good if samber/do also supports
Startupableinterface like:The mechanism of
Startupablecould be similar to theOnStarthook in uber/fx.This would provide a clear place to build connections, start background tasks, and fetch initial data.
Startupablevs. do startup in constructor#92 suggests doing startup work inside constructors by passing a context.Context.
Having a separate Startup function could be preferable in some cases:
NewXxx→Startup→Shutdowntemplate (which in our view makes the code cleaner, as the constructor only handles injections while Startup handles initializations).That said, #92 (the
InvokeContextidea) is not in conflict withStartupable. In some cases, we might still want to perform I/O operations during construction, depending on how we understand the business logic and layer the code.It could be beneficial if samber/do supported both approaches.