func (s *semaphore) Release() error {
	t := time.After(s.timeout)
	select {
	case <-s.sem:
		return nil
	case <-t:  
		return ErrIllegalRelease
	}
}
Release release sem
package sem
import (
	"errors"
	"time"
)
var (
	ErrNoTickets      = errors.New("semaphore: could not aquire semaphore")
	ErrIllegalRelease = errors.New("semaphore: can't release the semaphore without acquiring it first")
)
type SemInterface interface {
	Acquire() error
	Release() error
}
type semaphore struct {
	sem     chan struct{}
	timeout time.Duration  
}
func New(tickets int, timeout time.Duration) SemInterface {
	return &semaphore{
		sem:     make(chan struct{}, tickets),
		timeout: timeout,
	}
}
func (s *semaphore) Acquire() error {
	select {
	case s.sem <- struct{}{}:
		return nil
	case <-time.After(s.timeout):
		return ErrNoTickets
	}
}