class ReactorActorM::RactorActor
A shared state actor driven by Ruby Ractors.
Public Class Methods
new(data)
click to toggle source
# File lib/ractor_actor.rb, line 28 def initialize(data) @ractor = Ractor.new do state = nil loop do incoming = Ractor.recv case incoming.method when :get incoming.backchannel.send state when :set state = incoming.obj incoming.backchannel.send true when :kill break end end end @ractor.send RactorMessage.new :set, data _ = @value end
Public Instance Methods
get_value_with_timeout(timeout)
click to toggle source
# File lib/ractor_actor.rb, line 61 def get_value_with_timeout(timeout) m = RactorMessage.new :get @ractor.send m val = nil Timeout.timeout(timeout) do val = m.backchannel.take end val end
kill()
click to toggle source
# File lib/ractor_actor.rb, line 71 def kill m = RactorMessage.new :kill @ractor.send m _ = m.backchannel.take end
value()
click to toggle source
# File lib/ractor_actor.rb, line 49 def value m = RactorMessage.new :get @ractor.send m m.backchannel.take end
value=(new_value)
click to toggle source
# File lib/ractor_actor.rb, line 55 def value=(new_value) m = RactorMessage.new :set, new_value @ractor.send m _ = m.backchannel.take end