Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting IsClosed for Channel #486

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ func (ch *Channel) Close() error {
)
}

// IsClosed returns true if the channel is marked as closed, otherwise false
// is returned.
func (ch *Channel) IsClosed() bool {
return (atomic.LoadInt32(&ch.closed) == 1)
}

/*
NotifyClose registers a listener for when the server sends a channel or
connection exception in the form of a Connection.Close or Channel.Close method.
Expand Down
16 changes: 16 additions & 0 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,19 @@ func TestIsClosed(t *testing.T) {
t.Fatal("connection expected to be marked as closed")
}
}

// TestChannelIsClosed will test the public method IsClosed on a channel.
func TestChannelIsClosed(t *testing.T) {
conn := integrationConnection(t, "public channel.IsClosed()")
ch, _ := conn.Channel()

if ch.IsClosed() {
t.Fatalf("channel expected to not be marked as closed")
}

ch.Close()

if !ch.IsClosed() {
t.Fatal("channel expected to be marked as closed")
}
}