package app

import (
	"context"
	"sync"
)

type Lifecycle struct {
	Ctx    context.Context
	Cancel context.CancelFunc
	Wg     sync.WaitGroup
}

func (l *Lifecycle) Start() {
	l.Ctx, l.Cancel = context.WithCancel(context.Background())
}

func (l *Lifecycle) Stop() {
	if l.Cancel != nil {
		l.Cancel()
		l.Wg.Wait()
	}
}