Skip to content

Commit

Permalink
ethclient: add DialContext and Close (ethereum#16318)
Browse files Browse the repository at this point in the history
DialContext allows users to pass a Context object for cancellation.
Close closes the underlying RPC connection.
  • Loading branch information
Lorenzo Manacorda authored and sunfinite committed Aug 9, 2018
1 parent b3b088c commit b0d3cd5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ type Client struct {

// Dial connects a client to the given URL.
func Dial(rawurl string) (*Client, error) {
c, err := rpc.Dial(rawurl)
return DialContext(context.Background(), rawurl)
}

func DialContext(ctx context.Context, rawurl string) (*Client, error) {
c, err := rpc.DialContext(ctx, rawurl)
if err != nil {
return nil, err
}
Expand All @@ -51,6 +55,10 @@ func NewClient(c *rpc.Client) *Client {
return &Client{c}
}

func (ec *Client) Close() {
ec.c.Close()
}

// Blockchain Access

// BlockByHash returns the given full block.
Expand Down

0 comments on commit b0d3cd5

Please sign in to comment.