Cleanup the IQ result route API

Simplify the API in several ways:

- provide the context to the IQ result handler, making it possible to pass in
  extra context and handle timeouts within the handler.
- pass the stanza in as an IQ type, removing the need to always type-cast it
  in the handler
- remove Router.HandleIqResult and Router.HandleFuncIqResult. Since the router
  is private to Client nobody would ever use these, and they do not really make
  things simpler anyway.
This commit is contained in:
Wichert Akkerman
2019-10-29 11:02:41 +01:00
committed by Mickaël Rémond
parent 8088e3fa7e
commit 83bc8581fd
3 changed files with 56 additions and 40 deletions
+2 -2
View File
@@ -235,14 +235,14 @@ func (c *Client) Send(packet stanza.Packet) error {
// // Handle the result here
// })
//
func (c *Client) SendIQ(ctx context.Context, iq stanza.IQ, handler HandlerFunc) (*IqResultRoute, error) {
func (c *Client) SendIQ(ctx context.Context, iq stanza.IQ, handler IQResultHandlerFunc) (*IQResultRoute, error) {
if iq.Attrs.Type != "set" && iq.Attrs.Type != "get" {
return nil, ErrCanOnlySendGetOrSetIq
}
if err := c.Send(iq); err != nil {
return nil, err
}
return c.router.NewIqResultRoute(ctx, iq.Attrs.Id).HandlerFunc(handler), nil
return c.router.NewIQResultRoute(ctx, iq.Attrs.Id).HandlerFunc(handler), nil
}
// SendRaw sends an XMPP stanza as a string to the server.