package tool

import (
	"context"
)

// ProcessFunc 处理函数
type ProcessFunc func(e chan<- error)

// DeadlineProcess 超时处理器
func DeadlineProcess(ctx context.Context, f ProcessFunc) (err error) {
	result := make(chan error)
	go func() {
		defer close(result)
		f(result)
	}()
	select {
	case <-ctx.Done():
		return ctx.Err()
	case err = <-result:
		return err
	}
}
