I have just published SystemTimer 1.2 release on Gemcutter. This new version provides support for custom timeout exceptions, will let you specify sub-second timeouts and plays nicer with Ruby interpreters compiled with -disable-pthreads.
Install SystemTimer latest version with:
sudo gem install SystemTimer
Support for Custom Timeout Exceptions
This version adds support for custom timeout exceptions. This is useful when you want to avoid interference with other libraries already using/catching Timeout::Error (e.g. Net::HTTP)
require'system_timer'beginSystemTimer.timeout_after(5,MyCustomTimeoutException)do# Something that should be interrupted if it # takes too much time... even if blocked on # a system call!endrescueMyCustomTimeoutException=>e# Recovering strategyend
SystemTimer is going through too many layers to be able to reliably guarantee a sub-second timeout on all platforms, so – in the original SystemTimer implementation – the timeout had to be expressed as a number of seconds.
You can now specify timeouts as a fraction of a second and SystemTimer will do its best to reduce the timeout accordingly. e.g.
SystemTimer.timeout_after(0.5)do# timeout after 500msend
Note that for stability reasons SystemTimer will not allow you to go below 200ms, e.g.
SystemTimer.timeout_after(0.01)do# timeout at best after (uncompressable) 200ms # even if 10ms is requestedend
This feature is based on an idea and original contribution by Dmytro Shteflyuk (of Scribd fame).
Better Compatibility with -disable-pthreads
Changed SystemTimer implementation from using Mutex to Monitor. Mutex causes thread join errors when Ruby is compiled with -disable-pthreads.