Skip to content

Commit

Permalink
chore: add a TODO about removing the callback in Conn.AsyncWrite with…
Browse files Browse the repository at this point in the history
… UDP (#494)

Also eliminate the defer for callback in Conn.AsyncWrite with UDP
  • Loading branch information
panjf2000 authored Aug 18, 2023
1 parent b41addd commit 89672dc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions connection_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,15 @@ func (c *conn) SetKeepAlivePeriod(d time.Duration) error {

func (c *conn) AsyncWrite(buf []byte, callback AsyncCallback) error {
if c.isDatagram {
defer func() {
if callback != nil {
_ = callback(nil, nil)
}
}()
return c.sendTo(buf)
err := c.sendTo(buf)
// TODO: it will not go asynchronously with UDP, so calling a callback is needless,
// we may remove this branch in the future, please don't rely on the callback
// to do something important under UDP, if you're working with UDP, just call Conn.Write
// to send back your data.
if callback != nil {
_ = callback(nil, nil)
}
return err
}
return c.loop.poller.Trigger(c.asyncWrite, &asyncWriteHook{callback, buf})
}
Expand Down

0 comments on commit 89672dc

Please sign in to comment.