From bbe833bb5349ebabe111c569b23731aa5f177aca Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 30 Jan 2025 15:53:33 -0500 Subject: [PATCH] Add the RunShutdowner actor interface --- actor.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/actor.go b/actor.go index 52c26e7..7782d08 100644 --- a/actor.go +++ b/actor.go @@ -88,3 +88,23 @@ type Resettable interface { // invalid and any process which depends on it should be shut down. Reset(ctx context.Context) error } + +// RunShutdownable is any object that needs a context in order to shut down. +// Actors which implement this interface cannot implement the Runnable +// interface. This can be used to run an http.Server as an actor. +type RunShutdownable interface { + // Run is similar to [Runnable.Run], but takes no context and blocks + // until Shutdown has run and exited. It may also return when something + // goes wrong and it cannot continue, in which case it must return a + // non-nil error explaining why. Shutdown does not need to be called in + // the latter case. + Run() error + // Shutdown shuts down the actor. It must be called while Run is + // running, and it must unblock Run even if it fails, the context + // expires, it returns an error, etc. Shutdown must return when or + // before the context expires, and must return ctx.Err if there is no + // other error to be returned. If Shutdown returns any error, the object + // must be treated as invalid and any other process which depends on it + // should be shut down. + Shutdown(ctx context.Context) error +}