robustthread 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/robustthread.rb +16 -1
  2. metadata +2 -2
data/lib/robustthread.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # Copyright:: Copyright (c) 2009 Jared Kuolt
3
3
  # License:: MIT License
4
4
  require 'logger'
5
+ require 'timeout'
5
6
 
6
7
  class RobustThread
7
8
  # The Thread object, brah
@@ -54,7 +55,21 @@ class RobustThread
54
55
  Kernel.loop do
55
56
  break if self.say_goodnight
56
57
  block.call(*args)
57
- sleep sleep_seconds
58
+ # We want to sleep for the right amount of time, but we also don't
59
+ # want to wait until the sleep is done if our exit handler has been
60
+ # called so we iterate over a loop, sleeping only 0.1 and checking
61
+ # each iteration whether we need to die, and the timeout is a noop
62
+ # indicating we need to continue.
63
+ begin
64
+ Timeout.timeout(sleep_seconds) do
65
+ Kernel.loop do
66
+ break if self.say_goodnight
67
+ sleep 0.1
68
+ end
69
+ end
70
+ rescue Timeout::Error
71
+ # OK
72
+ end
58
73
  end
59
74
  end
60
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robustthread
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.4"
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Kuolt
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-08 00:00:00 -07:00
12
+ date: 2009-06-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15