With testing from @syd I found that there is an edge case in which this commit doesn't fulfill its promise:
When after remaining = endTime - now;, remaining is < 1 ms, e.g. 999 us, then, we'll call poll(timeout in ms = 0), and thus can return too early (but always less than 1 ms too early).
The same is true when remaining is e.g. 2.1 ms, then we'll pass 2 ms to poll, which may return TIMEOUT, and then we'll have waited for only 2 ms instead of 2.1.
I'll fix it by rounding up the milliseconds.