much-timeout 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/much-timeout.rb +9 -11
- data/lib/much-timeout/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
|
4
|
-
|
3
|
+
metadata.gz: 55949c8339e997def24be0b14f3319d93bb1679c887227c8b9f46a7b66c74e21e67181f090fe1b9535d19ffc26dc06387306a300260e05ca60b5af3b8a277bf4
|
4
|
+
data.tar.gz: 279f2401248030112cdcbb8fb4455970057e96b05f5d668b650c708ab889c759787103be4177e33ee0790e64317de66bd3701150be2b6ca8148bec7ba23074eb
|
5
5
|
SHA1:
|
6
|
-
|
7
|
-
|
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.
|
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
|
|
data/lib/much-timeout.rb
CHANGED
@@ -19,20 +19,18 @@ module MuchTimeout
|
|
19
19
|
reader, writer = IO.pipe
|
20
20
|
|
21
21
|
begin
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
data/lib/much-timeout/version.rb
CHANGED
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.
|
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-
|
13
|
+
date: 2016-06-22 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|