thread_io 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/thread_io.rb +42 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1ddae2ee6000eeb036b0ed8bccf23ca56dd80823ba7d4e86b8075b0751a1daa3
|
4
|
+
data.tar.gz: 012364aed013a8381c6755b0e3e1b60e1ba640dae28cdb05ac3f09b54631bb59
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a71ac3aab6e4f7f8a66d11cb62da0c4fe5ab45a0bbd37e6f041e87f6d70468dfa6a38e80028e60bf0237d5cd05e4edd69c1b2f927cfa4aafe4f789ed40c21961
|
7
|
+
data.tar.gz: 2da2efb69a9e4780c62116585e911cdb6d242b5a68dda37c45679e6c858a66209e1317a10629817306f013dddffc170b3e7ccc02ca552b431178b186c45d2b4c
|
data/lib/thread_io.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# this class loads the contents of a file using a Thread so that it's running
|
2
|
+
# outside your main Thread.
|
3
|
+
#
|
4
|
+
# Usage:
|
5
|
+
# tio = ThreadIO.new.read('/tmp/a_large_file.txt') # read a file
|
6
|
+
# ... do other stuff ...
|
7
|
+
#
|
8
|
+
# # optional loop until the file is read
|
9
|
+
# loop do
|
10
|
+
# breadk if tio.ready?
|
11
|
+
# sleep 1
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# tio.string # contains the contents of the file as one large String
|
15
|
+
class ThreadIO
|
16
|
+
attr_reader :string
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@ready = false
|
20
|
+
@string = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
# this method returns immediately and loads the file in the background
|
24
|
+
#
|
25
|
+
# path: the path to the file you want to read.
|
26
|
+
def read(path)
|
27
|
+
@ready = false
|
28
|
+
Thread.new do
|
29
|
+
@string = nil
|
30
|
+
@string = IO.read(path)
|
31
|
+
@ready = true
|
32
|
+
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def ready?
|
40
|
+
@ready
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thread_io
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Lunt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: a small class that loads files in the background via a Thread
|
14
|
+
email: jefflunt@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/thread_io.rb
|
20
|
+
homepage: https://github.com/jefflunt/thread_io
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.4.1
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: want a simple way to load large files in the backgroudn via a Thread? then
|
43
|
+
this library is for you.
|
44
|
+
test_files: []
|