package standby_ctrl

import (
	"context"
	"go.uber.org/zap"
	"time"
)

// Duration 持续时长控制器
func Duration(duration int64, play func(c context.Context) error) func(c context.Context) error {
	return func(c context.Context) error {
		zap.S().Infoln("待机持续时长控制器: ", duration)
		defer zap.S().Infoln("待机持续时长控制器结束: ", duration)

		if duration > 0 {
			ctx, cancel := context.WithTimeout(c, time.Duration(duration)*time.Second)
			defer cancel()
			c = ctx
		}

		return play(c)
	}
}
