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

bugfix: don't let channels be closed more than once #67

Merged
merged 1 commit into from
May 23, 2024
Merged
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
5 changes: 4 additions & 1 deletion internal/api/rust/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ func (c *RustClient) SendMessage(t ct.TestLike, roomID, text string) (eventID st

func (c *RustClient) TrySendMessage(t ct.TestLike, roomID, text string) (eventID string, err error) {
t.Helper()
var isChannelClosed atomic.Bool
ch := make(chan bool)
// we need a timeline listener before we can send messages, AND that listener must be attached to the
// same *Room you call .Send on :S
Expand All @@ -463,7 +464,9 @@ func (c *RustClient) TrySendMessage(t ct.TestLike, roomID, text string) (eventID
// else this will panic on the 2nd call.
kegsay marked this conversation as resolved.
Show resolved Hide resolved
if eventID == "" {
eventID = ev.ID
close(ch)
if isChannelClosed.CompareAndSwap(false, true) {
close(ch)
}
}
}
}
Expand Down
Loading