From 4770fb0186998245fd632f5767c9575999faac0f Mon Sep 17 00:00:00 2001 From: Lorenzo Manacorda Date: Thu, 19 Apr 2018 15:36:33 +0200 Subject: [PATCH] ethclient: add DialContext and Close (#16318) DialContext allows users to pass a Context object for cancellation. Close closes the underlying RPC connection. --- ethclient/ethclient.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 2973d6843888..ddffc6b9be2e 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -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 } @@ -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.