ractor_io 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ractor_io.rb +19 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf54ab67f82f962cbe2775f129d2b3dda7ede4d7b62fb9d0f8073027257b9514
4
- data.tar.gz: 1578c016bb11b9ed1c231c15428715a89f3c3869d7eacc65ea6e561121112ec3
3
+ metadata.gz: f67b66bca3a2c2c35ecc33c931f549f3f32b1e43be3f4587a27ac8c09a434aa7
4
+ data.tar.gz: b4adb978c7ba55dfec78994347632913a8cc51dc61f126db56a97469e58b3ac8
5
5
  SHA512:
6
- metadata.gz: f70fe4a5bf3c4afcf7331e5f5871c8ee0dc3fc3e298ec57c5f2c78235bb6c0f2736214edb3edb4fc2bfdff03ee5406cc2169572afcee2255bbf17e046ac5c954
7
- data.tar.gz: cbfd790166f4daf442aa8df1fc5403758c305201d56489ea31d8193b3846ac844c451ce9732d2d3a5dd2fc3e20ba9614e572ac0a49b568780f230c97a1fa1d0d
6
+ metadata.gz: dc14ca1b474fcc1320d766f4a6eb5716be770b99e3b757e013d2e68fd6f8a804d408a175643c1ce52a2cfa6016f6f89f76ec4b01a9917f75177b32c1d44d1864
7
+ data.tar.gz: e5ed4e5508b9966b3c858e3ffbaf9865ed13a6cceae4ab31abeef24a894ef27a1755ec587c4f4dc270f06a0043b63a1822abc872f11d670287fb48e59c73c418
data/lib/ractor_io.rb CHANGED
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # # optional loop until the file is read
9
9
  # loop do
10
- # breadk if rio.ready?
10
+ # break if rio.ready?
11
11
  # sleep 1
12
12
  # end
13
13
  #
@@ -15,7 +15,23 @@
15
15
  class RactorIO
16
16
  attr_reader :string
17
17
 
18
- def initialize
18
+ # move: if true, the Ractor will yield the loaded file using the `move` option of Ractor::yield.
19
+ # default: false
20
+ #
21
+ # NOTE: as of this writing, and having tested this against Ruby 3.1.x and
22
+ # 3.2.x, setting the `move` option to `true' for large amounts of data
23
+ # seems to cause a crash, at least on macOS. as a result this option is set
24
+ # to `false` by default, which will result in a lot of memory copying, and
25
+ # therefore increasing total memory consumption.
26
+ #
27
+ # In the meantime, see also https://github.com/jefflunt/thread_io -
28
+ # basically the same library as this, but using Threads only instead of
29
+ # Ractors, which has the advantage of sharing memory, if that's important to
30
+ # you. I haven't done extensive performance testing, so the perfornace
31
+ # difference between ractor_io and thread_io might not be very large for
32
+ # your particular use case.
33
+ def initialize(move: false)
34
+ @move = move
19
35
  @ready = false
20
36
  @string = nil
21
37
  end
@@ -28,7 +44,7 @@ class RactorIO
28
44
  @ready = false
29
45
  @string = nil
30
46
  r = Ractor.new do
31
- Ractor.yield(IO.read(Ractor.receive), move: true)
47
+ Ractor.yield(IO.read(Ractor.receive), move: @move)
32
48
  end
33
49
  r.send(path)
34
50
  @string = r.take
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ractor_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
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-01-01 00:00:00.000000000 Z
11
+ date: 2023-01-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a small class that loads files in the background via a Ractor
14
14
  email: jefflunt@gmail.com