thread_io 1.0.0 → 1.1.0
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/lib/thread_io.rb +17 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d83017966c70bad04d23df7017a90a50309872dee44297641e350ced951f3bab
|
4
|
+
data.tar.gz: 3098c3abd0813f490cfdc0df65186d9fe6cf1cd4640e9aa0405013e167810b79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0475b6f748d8da583806957f50f8c6a9ccb5de88306ec5d46d477e37dde3761935f37341af374a0672ef11b76c9112af4634a19eccdd7991bb10903d0dd363a
|
7
|
+
data.tar.gz: '0899c30a42eb6f9c8cedc65c2d5c8d43fc8e7753c9f4fe85df5276e8674e03784e0431b5957b7276564e0f80cf8aa39e1e5e6a0993d7df6ac03d18e8056484ee'
|
data/lib/thread_io.rb
CHANGED
@@ -7,17 +7,19 @@
|
|
7
7
|
#
|
8
8
|
# # optional loop until the file is read
|
9
9
|
# loop do
|
10
|
-
#
|
10
|
+
# break if tio.ready?
|
11
11
|
# sleep 1
|
12
12
|
# end
|
13
13
|
#
|
14
14
|
# tio.string # contains the contents of the file as one large String
|
15
15
|
class ThreadIO
|
16
|
-
attr_reader :string
|
16
|
+
attr_reader :string,
|
17
|
+
:lines
|
17
18
|
|
18
19
|
def initialize
|
19
20
|
@ready = false
|
20
21
|
@string = nil
|
22
|
+
@lines = nil
|
21
23
|
end
|
22
24
|
|
23
25
|
# this method returns immediately and loads the file in the background
|
@@ -36,6 +38,19 @@ class ThreadIO
|
|
36
38
|
nil
|
37
39
|
end
|
38
40
|
|
41
|
+
def read_lines(path)
|
42
|
+
@ready = false
|
43
|
+
Thread.new do
|
44
|
+
@lines = []
|
45
|
+
File.open(path, 'r') {|f| f.each_line{|l| @lines << l.chomp } }
|
46
|
+
@ready = true
|
47
|
+
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
39
54
|
def ready?
|
40
55
|
@ready
|
41
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thread_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: a small class that loads files in the background via a Thread
|
14
14
|
email: jefflunt@gmail.com
|