cmds 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cmds/io_handler.rb +36 -6
- data/lib/cmds/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb76b191ec12117d2d68bef750fe3f613d770cc5
|
4
|
+
data.tar.gz: 5afb4768e3fada0c9d088b2552ead175c46d7a94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce525833832fd9d2086296e587233e91c4fa86f76bd4ff2ba2913b49d8816a3dd6261f4b768316782598d5e215ab76dbf794591701f927318dbddcf2b2f96b1f
|
7
|
+
data.tar.gz: 9c03d0736dd8c17559c86211bcbf4a4d384703362cd3b954370417d51da6e0c9a27b3ae3600fda6a07fae1814af24fd27d181b5e60fd78f2914847eb73eb844b
|
data/lib/cmds/io_handler.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
class Cmds
|
2
|
+
# Class for handling IO from threads and passing it back via a {Queue} to
|
3
|
+
# the main thread for processing.
|
4
|
+
#
|
5
|
+
# NOTE These are one-use only! Don't try to reuse them.
|
6
|
+
#
|
2
7
|
class IOHandler
|
3
8
|
attr_accessor :in, :out, :err
|
4
9
|
|
@@ -6,6 +11,28 @@ class Cmds
|
|
6
11
|
@in = nil
|
7
12
|
@out = $stdout
|
8
13
|
@err = $stderr
|
14
|
+
|
15
|
+
# Initialize a thread-safe queue for passing output from the IO threads
|
16
|
+
# back to the main thread
|
17
|
+
#
|
18
|
+
# NOTE This used to be done in {#start}, but I was seeing intermittent
|
19
|
+
# failures on Travis from what look like thread race conditions,
|
20
|
+
# guessing that it's from output arriving before {#start} is
|
21
|
+
# called, which totally looks like it could happen.
|
22
|
+
#
|
23
|
+
# See the failure in
|
24
|
+
#
|
25
|
+
# https://travis-ci.org/nrser/qb/jobs/348609316
|
26
|
+
#
|
27
|
+
# Really, I'm surprised I haven't hit more issues with this
|
28
|
+
# half-ass threading shit.
|
29
|
+
#
|
30
|
+
# Anyways, I moved the queue creation here, see if it helps.
|
31
|
+
#
|
32
|
+
@queue = Queue.new
|
33
|
+
|
34
|
+
# Flag that is set to `true` when {#start} is called.
|
35
|
+
@started = false
|
9
36
|
end
|
10
37
|
|
11
38
|
def out= value
|
@@ -22,7 +49,7 @@ class Cmds
|
|
22
49
|
@out = block
|
23
50
|
end
|
24
51
|
|
25
|
-
# called in
|
52
|
+
# called in separate thread handling process IO
|
26
53
|
def thread_send_out line
|
27
54
|
@queue << [:out, line]
|
28
55
|
end
|
@@ -31,19 +58,22 @@ class Cmds
|
|
31
58
|
@err = block
|
32
59
|
end
|
33
60
|
|
34
|
-
# called in
|
61
|
+
# called in separate thread handling process IO
|
35
62
|
def thread_send_err line
|
36
63
|
@queue << [:err, line]
|
37
64
|
end
|
38
|
-
|
65
|
+
|
66
|
+
# called in separate thread handling process IO
|
39
67
|
def thread_send_line sym, line
|
40
68
|
@queue << [sym, line]
|
41
69
|
end
|
42
70
|
|
43
71
|
def start
|
44
|
-
|
45
|
-
|
46
|
-
|
72
|
+
if @started
|
73
|
+
raise "This handler has already been started / run"
|
74
|
+
end
|
75
|
+
|
76
|
+
@started = true
|
47
77
|
|
48
78
|
# if out is a proc, it's not done
|
49
79
|
out_done = ! @out.is_a?(Proc)
|
data/lib/cmds/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nrser
|