Fix overflow in `kqueue` backend
Closes #111
@mitchellh I managed to write a test to avoid regressions but I'm not sure it's deterministic, should I still add it?
While discussing with @steeve and re-reading the issue, I think it's better to add more context. There are basically two ways we can solve that.
1. Cap the amount of completion executed per tick
This is simply breaking from the loop as I did in this PR.
One issue with that is that, if we are in loop.run(.once), we will potentially "miss" completions because we are capped to 256 completions in one tick. We will thus give back control to the user and the remaining completions will be handled in the next tick.
2. Drain all the completions in one tick
For that, we need to add another loop around the while (self.completions.pop()) |c| { ... } block, so that we handle all the completions that are ready.
One issue with this solution is that it can end up needing multiple call to kevent_syscall and it kind of feels weird with respect to the .once
So, in the end, that's why I went for the first solution, but I can get that it's not what you would expect @mitchellh. Let me know what you feel is best, and I'll make it work 😁
Gentle ping @mitchellh
Apologies, I just got our tests passing again. Let me take a look at this now :)
Alright, this looks good, at least to start. I think the caveat that once may not complete everything is reasonable.