Skip to content

How to know that the connection was closed #533

@matheuscscp

Description

@matheuscscp

I have a Goroutine on my server that should return if the connection is closed. How can I know if it was closed? Is there a channel that is closed when that happens or something similar? I'd like to write something like this:

conn, err := websocket.Accept(w, r, nil)
// ...

select {
case <-ctx.Done():
	// do something if the ctx of my function is done
case something: // some event selection expression that happens when conn is closed
	// release resources now that conn is closed
	return
}

Is this possible? Are there any workarounds?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions