rbgo 0.2.7 → 0.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec171658e61d3d64d313126f3b3ee709565a4676624a513982c73d531c4c2ce8
4
- data.tar.gz: 7266385dc226a8643dae466209ec674e59390fee1faabfbba39e85d578d875a6
3
+ metadata.gz: 88f583cbc3309a81e56fa7388a94b12e221be18ee671e40075dc1d2a531a1387
4
+ data.tar.gz: 66adc91902e07196656a01fbba5bd5c4f3e451f670b3da62ea1f2b9079b8f225
5
5
  SHA512:
6
- metadata.gz: 42f49f6cade30b7f4ebc6ac57c2ff9386d09256032cec1d87d11ca9f2b5b7f0c4b92e56c1db593066ddebfbb7f6ea208a2de9f64c721332268c0e0b10fddeba2
7
- data.tar.gz: 637bdfec998a93e8aadbef3d84d0ffc6faf1744b41f877e8faed3de349b3a77ecc80662822dbc6816302e8b5cbe7109b1a2c0fe58b52938095eb6b90e9de260e
6
+ metadata.gz: dc11f265924a159752c9664a53668a7e8e5495693c1b71807017410699587ff1e165256dd574a3a7129924aae440c8227dc9cc0127d7596c726f312839e42577
7
+ data.tar.gz: 6f255f61b6c4e5ab6284a94f67df012b356fd1ccbb25f1110b61dba9954a07bde780b8778be8c9574f1c48f82074391fd559b30816d4dffe9de763fa8c28a163
data/README.md CHANGED
@@ -135,9 +135,6 @@ IOMachine wrap nio4r to do IO operation asynchronously.
135
135
 
136
136
  support platforms: MRI, JRuby.
137
137
 
138
- *Not supported platform: Truffleruby*
139
-
140
-
141
138
  ```ruby
142
139
  require 'rbgo'
143
140
 
data/lib/rbgo/actor.rb CHANGED
@@ -35,10 +35,9 @@ module Rbgo
35
35
  private
36
36
 
37
37
  def start_msg_loop
38
- CoRun::Routine.new(new_thread: false) do
38
+ CoRun::Routine.new(new_thread: true) do
39
39
  while msg = mail_box.deq
40
40
  handler.call(msg, self) rescue nil
41
- Fiber.yield
42
41
  end
43
42
  end
44
43
  end
data/lib/rbgo/corun.rb CHANGED
@@ -34,6 +34,16 @@ module Rbgo
34
34
  end
35
35
  end
36
36
 
37
+ def self.read_partial_from(io, maxlen:)
38
+ if is_in_corun_fiber?
39
+ return "" if maxlen == 0
40
+ receipt = Scheduler.instance.io_machine.do_read_partial(io, maxlen: maxlen)
41
+ Fiber.yield [YIELD_IO_OPERATION, receipt]
42
+ else
43
+ io.readpartial(maxlen)
44
+ end
45
+ end
46
+
37
47
  def self.write_to(io, str:)
38
48
  if is_in_corun_fiber?
39
49
  receipt = Scheduler.instance.io_machine.do_write(io, str: str)
@@ -316,6 +326,10 @@ module Rbgo
316
326
  CoRun.read_line_from(self, sep: sep, limit: limit)
317
327
  end
318
328
 
329
+ def yield_read_partial(maxlen)
330
+ CoRun.read_partial_from(self, maxlen: maxlen)
331
+ end
332
+
319
333
  def yield_write(str)
320
334
  CoRun.write_to(self, str: str)
321
335
  end
@@ -59,6 +59,13 @@ module Rbgo
59
59
  receipt
60
60
  end
61
61
 
62
+ def do_read_partial(io, maxlen:)
63
+ op = [:register_read_partial, io, maxlen]
64
+ receipt = IOReceipt.new(op)
65
+ actor.send_msg(receipt)
66
+ receipt
67
+ end
68
+
62
69
 
63
70
  def close
64
71
  actor.close
@@ -91,6 +98,8 @@ module Rbgo
91
98
  handle_read_msg(receipt, actor)
92
99
  when :register_read_line
93
100
  handle_read_line_msg(receipt, actor)
101
+ when :register_read_partial
102
+ handle_read_partial_msg(receipt, actor)
94
103
  when :register_write
95
104
  handle_write_msg(receipt, actor)
96
105
  end
@@ -119,6 +128,44 @@ module Rbgo
119
128
  end
120
129
 
121
130
 
131
+ def handle_read_partial_msg(receipt, actor)
132
+ op = receipt.registered_op
133
+ io = op[1]
134
+ maxlen = op[2]
135
+ res = ""
136
+
137
+ monitor = register(receipt, interest: :r)
138
+ return if monitor.nil?
139
+
140
+ monitor.value ||= []
141
+ monitor.value[0] = proc do
142
+ notify_blk = proc do
143
+ monitors.delete(monitor.io)
144
+ monitor.close
145
+ receipt.res = res
146
+ receipt.notify
147
+ end
148
+ catch :exit do
149
+ begin
150
+ buf = io.read_nonblock(maxlen, exception: false)
151
+ rescue Exception => ex
152
+ notify_blk.call
153
+ STDERR.puts ex
154
+ throw :exit
155
+ end
156
+ if buf == :wait_readable
157
+ throw :exit
158
+ elsif buf.nil?
159
+ notify_blk.call
160
+ throw :exit
161
+ end
162
+ res << buf
163
+ notify_blk.call
164
+ end
165
+ end
166
+ actor.send_msg :do_select
167
+ end
168
+
122
169
  def handle_read_line_msg(receipt, actor)
123
170
  op = receipt.registered_op
124
171
  io = op[1]
data/lib/rbgo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rbgo
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbgo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wang Yin