ractor_io 1.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ractor_io.rb +46 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bf54ab67f82f962cbe2775f129d2b3dda7ede4d7b62fb9d0f8073027257b9514
4
+ data.tar.gz: 1578c016bb11b9ed1c231c15428715a89f3c3869d7eacc65ea6e561121112ec3
5
+ SHA512:
6
+ metadata.gz: f70fe4a5bf3c4afcf7331e5f5871c8ee0dc3fc3e298ec57c5f2c78235bb6c0f2736214edb3edb4fc2bfdff03ee5406cc2169572afcee2255bbf17e046ac5c954
7
+ data.tar.gz: cbfd790166f4daf442aa8df1fc5403758c305201d56489ea31d8193b3846ac844c451ce9732d2d3a5dd2fc3e20ba9614e572ac0a49b568780f230c97a1fa1d0d
data/lib/ractor_io.rb ADDED
@@ -0,0 +1,46 @@
1
+ # this class loads the contents of a file using a Ractor so that it's running
2
+ # outside your main Ractor.
3
+ #
4
+ # Usage:
5
+ # rio = RactorIO.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 rio.ready?
11
+ # sleep 1
12
+ # end
13
+ #
14
+ # rio.string # contains the contents of the file as one large String
15
+ class RactorIO
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
+ Thread.new do
28
+ @ready = false
29
+ @string = nil
30
+ r = Ractor.new do
31
+ Ractor.yield(IO.read(Ractor.receive), move: true)
32
+ end
33
+ r.send(path)
34
+ @string = r.take
35
+ @ready = true
36
+
37
+ nil
38
+ end
39
+
40
+ nil
41
+ end
42
+
43
+ def ready?
44
+ @ready
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ractor_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 Ractor
14
+ email: jefflunt@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ractor_io.rb
20
+ homepage: https://github.com/jefflunt/ractor_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 Ractor? then
43
+ this library is for you.
44
+ test_files: []