Skip to content

Fix channel sink#30

Open
Adirio wants to merge 3 commits into
docker:mainfrom
Adirio:fix-channel-sink
Open

Fix channel sink#30
Adirio wants to merge 3 commits into
docker:mainfrom
Adirio:fix-channel-sink

Conversation

@Adirio
Copy link
Copy Markdown

@Adirio Adirio commented May 3, 2018

Fixes #29

It uses the default case lower priority to check first if the Channel sink is closed.

IK-Adrian added 2 commits May 3, 2018 15:32
Signed-off-by: Adrián Orive <aorive@ikerlan.es>
Signed-off-by: Adrián Orive <aorive@ikerlan.es>
Comment thread channel.go Outdated
case <-ch.closed:
return ErrSinkClosed
default:
ch.C <- event
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will block forever is ch.closed is closed after the check.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit should fix this. Nested selects are not as pretty as flat ones but as Go chooses randomly if two of the select cases can be performed at entering, this is the only way to force a check on the channel before while still keeping the non-blocking functionality.

Avoid blocking on Channel.Write if Channel.Close is called after the check is done
@thaJeztah
Copy link
Copy Markdown
Member

@stevvooe ptal

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Channel.Write after Channel.Close

4 participants