Spawn goroutines with startup guarantees. Start blocks until the goroutine is scheduled. StartWithReady blocks until the goroutine signals readiness. StartWithStop passes a stop function into the goroutine.
Start
Blocks until the goroutine has actually started executing. Useful in tests where you need the routine to be running before proceeding.
Parent context. Cancellation is propagated to the goroutine.
fn
Func
The function to execute. Signature: func(ctx context.Context) error
opts
...GoOption
Functional options.
Behavior
Same middleware chain as Go: panic recovery, resilience, user middlewares, metrics, tracing, stall detection.
If a WithLimiter semaphore is set, it is acquired before spawning.
The goroutine is spawned and Start blocks until it begins executing.
Errors are handled via the ErrorHandler (default: slog.ErrorContext).
Example
gofuncy.Start(ctx,func(ctxcontext.Context)error{// This goroutine is guaranteed to be running// by the time Start returns.returnserve(ctx)})// Safe to send requests — the server is running.
StartWithReady
Blocks until the goroutine signals readiness by calling ready(). If the function returns before calling ready(), StartWithReady unblocks anyway.
Parent context. Cancellation is propagated to the goroutine.
fn
func(ctx context.Context, ready ReadyFunc) error
The function to execute. Call ready() to signal readiness.
opts
...GoOption
Functional options.
Behavior
Same middleware chain as Go and Start.
StartWithReady blocks until either ready() is called or fn returns — whichever comes first.
The ready function is safe to call multiple times (protected by sync.Once).
If fn panics or returns an error before calling ready(), StartWithReady still unblocks and the error is routed to the error handler.
Example
gofuncy.StartWithReady(ctx,func(ctxcontext.Context,readyReadyFunc)error{ln,err:=net.Listen("tcp",":8080")iferr!=nil{returnerr}ready()// signal: listener is upreturnhttp.Serve(ln,handler)})// At this point, the listener is guaranteed to be accepting connections.
StartWithStop
Spawns a fire-and-forget goroutine that receives a stop function. Calling stop cancels the goroutine's context from within, signaling it to shut down. The stop function is safe to call multiple times.