The test suite passes with this change (just a demo): https://github.com/jjb/timeout/pull/6/files
If that's acceptable, then the code can be cleaned up like so, with the benefits of being more readable and also creating fewer objects per invocation: https://github.com/jjb/timeout/pull/5/files
If it's not acceptable, I could make a PR which adds a test.