use the correct context

This commit is contained in:
a 2023-06-26 03:31:07 -05:00
parent 18f2af8f63
commit 090dd88342
No known key found for this signature in database
GPG Key ID: 374BC539FE795AF0

View File

@ -15,6 +15,7 @@ import (
type Dialer struct { type Dialer struct {
connect js.Value connect js.Value
opts *SocketOptions opts *SocketOptions
ctx context.Context
} }
type SocketOptions struct { type SocketOptions struct {
@ -28,7 +29,7 @@ func NewDialer(ctx context.Context, options *SocketOptions) (*Dialer, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Dialer{connect: connect, opts: options}, nil return &Dialer{connect: connect, opts: options, ctx: ctx}, nil
} }
func (d *Dialer) Dial(ctx context.Context, network, addr string) (net.Conn, error) { func (d *Dialer) Dial(ctx context.Context, network, addr string) (net.Conn, error) {
@ -52,7 +53,7 @@ func (d *Dialer) Dial(ctx context.Context, network, addr string) (net.Conn, erro
sock.reader = sock.socket.Get("readable").Call("getReader") sock.reader = sock.socket.Get("readable").Call("getReader")
sock.options = d.opts sock.options = d.opts
sock.ctx, sock.cn = context.WithCancel(context.Background()) sock.ctx, sock.cn = context.WithCancel(d.ctx)
{ {
sock.rd = jsutil.ConvertReadableStreamToReader(sock.reader) sock.rd = jsutil.ConvertReadableStreamToReader(sock.reader)