1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-08-16 10:08:12 +02:00

allow multiple OnRecv and OnSend

This commit is contained in:
Keegan Carruthers-Smith 2018-05-01 19:02:17 +01:00
parent 2ed59d3304
commit a3d86c792f
2 changed files with 20 additions and 12 deletions

View file

@ -13,13 +13,13 @@ type ConnOpt func(*Conn)
// OnRecv causes all requests received on conn to invoke f(req, nil)
// and all responses to invoke f(req, resp),
func OnRecv(f func(*Request, *Response)) ConnOpt {
return func(c *Conn) { c.onRecv = f }
return func(c *Conn) { c.onRecv = append(c.onRecv, f) }
}
// OnSend causes all requests sent on conn to invoke f(req, nil) and
// all responses to invoke f(nil, resp),
func OnSend(f func(*Request, *Response)) ConnOpt {
return func(c *Conn) { c.onSend = f }
return func(c *Conn) { c.onSend = append(c.onSend, f) }
}
// LogMessages causes all messages sent and received on conn to be