Timeouts

Neffos provides a wrapper of neffos.Namespaces and neffos.Events structures to deal with custom Write and Read deadtimes/timeouts, it's the neffos.WithTimeoutarrow-up-right.

Its outline looks like this:

// WithTimeout completes the `ConnHandler` interface.
// Can be used to register namespaces and events or just events on an empty namespace
// with Read and Write timeouts.
//
// See `New` and `Dial`.
type WithTimeout struct {
    ReadTimeout  time.Duration
    WriteTimeout time.Duration

    Namespaces Namespaces
    Events     Events
}

It's easy to set timeouts, instead of var events = neffos.Namespaces{"namespace": neffos.Events: ...} you just wrap it with neffos.WithTimeout like this:

var events = neffos.WithTimeout {
    ReadTimeout:  60 * time.Second,
    WriteTimeout: 60 * time.Second,

    Namespaces: neffos.Namespaces {
        "namespace": neffos.Events {
            "onMyEvent": func(c *neffos.NSConn, msg neffos.Message) error {
                // [...]
            },
        },
    },
}

or for empty namespace:

Of cource you could provide those timeouts based on what Upgrader and Dialer implementations are being used on Server and Client respectfully, i.e the gorillaarrow-up-right's one has ReadTimeout and WriteTimeout optional fields that you can set on a custom gorilla/websocket.Upgrader structure but if you want a universal way to set your own timeouts in the connection handler level(namespaces, events) use the neffos.WithTimeout instead.

Last updated