Skip to content

Commit

Permalink
Add bufcon.DialContext(context.Context)
Browse files Browse the repository at this point in the history
for use with grpc.WithContextDial DialOption

Signed-off-by: Ed Warnicke <hagbard@gmail.com>
  • Loading branch information
edwarnicke committed Sep 14, 2021
1 parent 5bfc05f commit 614f01e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/bufconn/bufconn.go
Expand Up @@ -21,6 +21,7 @@
package bufconn

import (
"context"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -86,8 +87,17 @@ func (l *Listener) Addr() net.Addr { return addr{} }
// providing it the server half of the connection, and returns the client half
// of the connection.
func (l *Listener) Dial() (net.Conn, error) {
return l.DialContext(context.Background())
}

// DialContext creates an in-memory full-duplex network connection, unblocks Accept by
// providing it the server half of the connection, and returns the client half
// of the connection. If ctx is Done, returns ctx.Err()
func (l *Listener) DialContext(ctx context.Context) (net.Conn, error) {
p1, p2 := newPipe(l.sz), newPipe(l.sz)
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-l.done:
return nil, errClosed
case l.ch <- &conn{p1, p2}:
Expand Down

0 comments on commit 614f01e

Please sign in to comment.