Skip to content

Commit b15eb66

Browse files
Lorenzo Manacordafjl
authored andcommitted
ethclient: add DialContext and Close (#16318)
DialContext allows users to pass a Context object for cancellation. Close closes the underlying RPC connection.
1 parent a16f12b commit b15eb66

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ethclient/ethclient.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ type Client struct {
3939

4040
// Dial connects a client to the given URL.
4141
func Dial(rawurl string) (*Client, error) {
42-
c, err := rpc.Dial(rawurl)
42+
return DialContext(context.Background(), rawurl)
43+
}
44+
45+
func DialContext(ctx context.Context, rawurl string) (*Client, error) {
46+
c, err := rpc.DialContext(ctx, rawurl)
4347
if err != nil {
4448
return nil, err
4549
}
@@ -51,6 +55,10 @@ func NewClient(c *rpc.Client) *Client {
5155
return &Client{c}
5256
}
5357

58+
func (ec *Client) Close() {
59+
ec.c.Close()
60+
}
61+
5462
// Blockchain Access
5563

5664
// BlockByHash returns the given full block.

0 commit comments

Comments
 (0)