Skip to content

Commit

Permalink
Add client instance to onconnect function (#73)
Browse files Browse the repository at this point in the history
* Update client.go

Add client instance to onconnect function

* Update rsocket_test.go

Add client instance to onconnect function
  • Loading branch information
kingljl authored Sep 27, 2020
1 parent fdb6a37 commit 12c8ef4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type ClientBuilder interface {
// OnClose register handler when client socket closed.
OnClose(func(error)) ClientBuilder
// OnConnect register handler when client socket connected.
OnConnect(func(error)) ClientBuilder
OnConnect(func(Client,error)) ClientBuilder
// Acceptor set acceptor for RSocket client.
Acceptor(acceptor ClientSocketAcceptor) ToClientStarter
}
Expand Down Expand Up @@ -91,7 +91,7 @@ type clientBuilder struct {
setup *socket.SetupInfo
acceptor ClientSocketAcceptor
onCloses []func(error)
onConnects []func(error)
onConnects []func(Client,error)
connectTimeout time.Duration
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func (cb *clientBuilder) Fragment(mtu int) ClientBuilder {
return cb
}

func (cb *clientBuilder) OnConnect(fn func(error)) ClientBuilder {
func (cb *clientBuilder) OnConnect(fn func(Client,error)) ClientBuilder {
cb.onConnects = append(cb.onConnects, fn)
return cb
}
Expand Down Expand Up @@ -215,11 +215,11 @@ func (cb *clientBuilder) Start(ctx context.Context) (client Client, err error) {

// trigger OnConnect
if len(cb.onConnects) > 0 {
var onConnects []func(error)
var onConnects []func(Client,error)
onConnects, cb.onConnects = cb.onConnects, nil
go func() {
for _, onConnect := range onConnects {
onConnect(err)
onConnect(client,err)
}
}()
}
Expand Down
2 changes: 1 addition & 1 deletion rsocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ func TestContextTimeout(t *testing.T) {

connected := make(chan bool)
cli, err := Connect().
OnConnect(func(err error) {
OnConnect(func(c Client,err error) {
connected <- err == nil
}).
ConnectTimeout(100 * time.Millisecond).
Expand Down

0 comments on commit 12c8ef4

Please sign in to comment.