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

Replace various update channels with one unique channel #137

Merged
merged 5 commits into from
Aug 16, 2017
Merged

Conversation

emersion
Copy link
Owner

@emersion emersion commented Aug 15, 2017

  • Maybe create one Update struct per update type?

@jim-minter, what do you think?

Fixes #136

@codecov
Copy link

codecov bot commented Aug 15, 2017

Codecov Report

Merging #137 into v1 will decrease coverage by <.01%.
The diff coverage is 84.61%.

Impacted file tree graph

@@           Coverage Diff            @@
##              v1    #137      +/-   ##
========================================
- Coverage   74.5%   74.5%   -0.01%     
========================================
  Files         31      31              
  Lines       3271    3251      -20     
========================================
- Hits        2437    2422      -15     
+ Misses       550     544       -6     
- Partials     284     285       +1
Impacted Files Coverage Δ
client/client.go 66.66% <84.61%> (-1.6%) ⬇️
server/conn.go 73.79% <0%> (+1.6%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc58f30...930b158. Read the comment docs.

client/client.go Outdated
go func() {
c.Errors <- resp
c.Updates <- resp

Choose a reason for hiding this comment

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

I don't think it's legitimate to put this in a separate go-routine: if sending to the channel blocks and multiple goroutines exist trying to send different items, isn't the channel item ordering undefined again?
I think the library has to block here, and the user must be responsible for consuming from the channel in parallel with the function call (or somehow be very confident their channel buffer size is large enough to avoid deadlock).

Choose a reason for hiding this comment

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

(this comment applies throughout this PR)

Copy link
Owner Author

Choose a reason for hiding this comment

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

You're right, fixed!

client/client.go Outdated
// A channel to which unilateral updates from the server will be sent. An
// update can be one of: *imap.StatusResp, *imap.MailboxStatus, *imap.Message,
// *ExpungeUpdate. Note that blocking this channel blocks the whole client,
// so it's recommended to use a buffered channel.

Choose a reason for hiding this comment

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

I think the IDLE command is an example where the number of updates that will be received may not be knowable in advance; in this case there is a risk of filling the channel and deadlock occuring if the channel is not emptied in parallel. I think the best recommendation would be for the channel to be consumed in parallel from a separate goroutine during execution of a request, (and for the user to ensure that the channel is emptied once the request returns, so that any updates have been synced to the local state).

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah, that's a good point, I changed the docs. In general, it's unsafe to rely on the server only sending a given number of responses and it's better to use separate goroutines.

@jim-minter
Copy link

Looks good - many thanks @emersion!

@emersion emersion merged commit 1cb024e into v1 Aug 16, 2017
@emersion emersion deleted the updates-chan branch August 16, 2017 15:26
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.

None yet

2 participants