much-timeout 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA512:
3
- data.tar.gz: 2fa361b98af1eaae451ed91a28d1d9641777eab828716d4c10a3411170f0bc6de3dc8f4c3855b368a2e29badcb23f8082b4d4b237fa89af72c4660a585a80263
4
- metadata.gz: 265aaee5763dc7fc6d5208ea42ceefb11dc8cfeb5f70173885c0bd0206ff41dcbe405d9c233b2d6948f72e21d6a1fb9506333852be349c81841db08a2a050afd
3
+ metadata.gz: 55949c8339e997def24be0b14f3319d93bb1679c887227c8b9f46a7b66c74e21e67181f090fe1b9535d19ffc26dc06387306a300260e05ca60b5af3b8a277bf4
4
+ data.tar.gz: 279f2401248030112cdcbb8fb4455970057e96b05f5d668b650c708ab889c759787103be4177e33ee0790e64317de66bd3701150be2b6ca8148bec7ba23074eb
5
5
  SHA1:
6
- data.tar.gz: 0bbfd0ebdc797ec310f8bc33f39e40a51973e4b5
7
- metadata.gz: 3239b0fddda2d296afeab424878e399219bf5fa7
6
+ metadata.gz: d18a32435d845e9c073cda374377e8ad266eb822
7
+ data.tar.gz: a099d9630bd0639f17ce857faf3b87659c1f4876
data/README.md CHANGED
@@ -17,7 +17,7 @@ MuchTimeout.timeout(5) do
17
17
  end
18
18
  ```
19
19
 
20
- MuchTimeout, in its basic form, is a replacement for Timeout. The main difference is that `IO.select` on an internal pipe is the mechanism for detecting the timeout. Another difference is that the block is executed in a separate thread while the select/monitoring occurs in the main thread.
20
+ MuchTimeout, in its basic form, is a replacement for Timeout. The main difference is that `IO.select` on an internal pipe is the mechanism for detecting the timeout.
21
21
 
22
22
  **Note**: like Timeout, **`Thread#raise` is used to interrupt the block**. This technique is [widely](http://blog.headius.com/2008/02/ruby-threadraise-threadkill-timeoutrb.html) [considered](http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/) to be [dangerous](http://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying/). Be aware and use responsibly.
23
23
 
@@ -19,20 +19,18 @@ module MuchTimeout
19
19
  reader, writer = IO.pipe
20
20
 
21
21
  begin
22
- block_thread ||= Thread.new do
23
- begin
24
- block.call
25
- ensure
26
- writer.write_nonblock(PIPE_SIGNAL) rescue false
22
+ main_thread = Thread.current
23
+ io_select_thread ||= Thread.new do
24
+ if !::IO.select([reader], nil, nil, seconds)
25
+ main_thread.raise exception_klass
27
26
  end
28
27
  end
29
- if !!::IO.select([reader], nil, nil, seconds)
30
- block_thread.join
31
- else
32
- block_thread.raise exception_klass
33
- block_thread.join
28
+ begin
29
+ block.call
30
+ ensure
31
+ writer.write_nonblock(PIPE_SIGNAL) rescue false
32
+ io_select_thread.join
34
33
  end
35
- block_thread.value
36
34
  ensure
37
35
  reader.close rescue false
38
36
  writer.close rescue false
@@ -1,3 +1,3 @@
1
1
  module MuchTimeout
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: much-timeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2016-06-07 00:00:00 Z
13
+ date: 2016-06-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert