diff --git a/metadapta.go b/metadapta.go index 87cf3f3..5c30413 100644 --- a/metadapta.go +++ b/metadapta.go @@ -4,7 +4,6 @@ import "io" import "fmt" import "net" import "sync" -import "context" import "git.tebibyte.media/sashakoshka/hopp/tape" import "git.tebibyte.media/sashakoshka/go-util/sync" @@ -24,6 +23,7 @@ type a struct { sendLock sync.Mutex transMap map[int64] *transA transChan chan *transA + done chan struct { } err error } @@ -35,12 +35,14 @@ func AdaptA(underlying net.Conn, party Party) Conn { party: party, transMap: make(map[int64] *transA), transChan: make(chan *transA), + done: make(chan struct { }), } go conn.receive() return conn } func (this *a) Close() error { + close(this.done) return this.underlying.Close() } @@ -61,12 +63,12 @@ func (this *a) OpenTrans() (Trans, error) { return trans, nil } -func (this *a) AcceptTrans(ctx context.Context) (Trans, error) { +func (this *a) AcceptTrans() (Trans, error) { select { case trans := <- this.transChan: return trans, nil - case <- ctx.Done(): - return nil, ctx.Err() + case <- this.done: + return nil, fmt.Errorf("could not accept transaction: %w", io.EOF) } } diff --git a/metadaptb.go b/metadaptb.go index a436cb5..0526ebb 100644 --- a/metadaptb.go +++ b/metadaptb.go @@ -29,8 +29,8 @@ func (this *b) OpenTrans() (Trans, error) { return transB { underlying: stream }, nil } -func (this *b) AcceptTrans(ctx context.Context) (Trans, error) { - stream, err := this.underlying.AcceptStream(ctx) +func (this *b) AcceptTrans() (Trans, error) { + stream, err := this.underlying.AcceptStream(context.Background()) if err != nil { return nil, err } return transB { underlying: stream }, nil }