Skip to content

Document how to have a separate idle and read timeout #87

Description

@nhooyr
func read(ctx context.Context, c *websocket.Conn) ([]byte, error) {
	ctx, cancel := context.WithTimeout(ctx, time.Minute*30)
	defer cancel()

	_, r, err := c.Reader(ctx)
	if err != nil {
		return nil, err
	}

	// One minute max to read the received message.
	time.AfterFunc(time.Minute, cancel)

	return ioutil.ReadAll(r)
}

That code should be good in an example under Reader.

Related #86

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions