smallnest / chanx

unbounded chan
MIT License
432 stars 63 forks source link

Why not Peek first and then Pop in drain ? #18

Closed molon closed 9 months ago

molon commented 9 months ago

https://github.com/smallnest/chanx/blob/0aaad016beec0e4b4b7bd571b0960e337cd48f2e/unbounded_chan.go#L54-L66

Why not Peek first and then Pop? There is a possibility that out did not receive this Pop data because ctx.Done was triggered first after Pop from buf.

molon commented 9 months ago

Of course, after thinking about it, since ctx.Done, it seems not very necessary.

smallnest commented 9 months ago

This is drain, if users have selected ctx.Done, then drain is finished