Files
zt/tests/testutil/timeout_underlay.go
zeekay 873220f90b rebrand: openziti → hanzozt (Hanzo Zero Trust)
Global rebrand of all OpenZiti references to Hanzo ZT:
- Go module paths: github.com/openziti/* → github.com/hanzozt/*
- Docker images: openziti/* → hanzozt/*
- Java packages: org.openziti.* → org.hanzozt.*
- Brand: OpenZiti → Hanzo ZT
- URLs: openziti.io → hanzozt.dev
2026-02-18 16:13:53 -08:00

43 lines
859 B
Go

package testutil
import (
"time"
"github.com/hanzozt/channel/v4"
"github.com/pkg/errors"
)
func NewTimeoutUnderlayFactory(factory channel.UnderlayFactory, timeout time.Duration) *UnderlayFactoryWrapper {
return &UnderlayFactoryWrapper{
timeout: timeout,
wrapped: factory,
}
}
type UnderlayFactoryWrapper struct {
timeout time.Duration
wrapped channel.UnderlayFactory
}
func (self *UnderlayFactoryWrapper) Create(timeout time.Duration) (channel.Underlay, error) {
underlayC := make(chan channel.Underlay, 1)
errC := make(chan error, 1)
go func() {
u, err := self.wrapped.Create(timeout)
if err != nil {
errC <- err
} else {
underlayC <- u
}
}()
select {
case underlay := <-underlayC:
return underlay, nil
case err := <-errC:
return nil, err
case <-time.After(self.timeout):
return nil, errors.New("timed out")
}
}