Class: Shmactor

Inherits:
Object
  • Object
show all
Defined in:
lib/shmactor.rb,
lib/shmactor/port.rb,
lib/shmactor/closed_error.rb

Defined Under Namespace

Classes: ClosedError, Port

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Shmactor

Returns a new instance of Shmactor.



10
11
12
13
# File 'lib/shmactor.rb', line 10

def initialize(*args, &block)
  @queue = Port.new
  @thread = Thread.new { instance_exec(*args, &block) }
end

Class Method Details

.activate!Object



6
# File 'lib/shmactor.rb', line 6

def activate! = @activated = true

.activated?Boolean

Returns:

  • (Boolean)


7
# File 'lib/shmactor.rb', line 7

def activated? = @activated

Instance Method Details

#<<(object, move: false) ⇒ Object



16
# File 'lib/shmactor.rb', line 16

def <<(object, move: false) = @queue << object

#closeObject



19
# File 'lib/shmactor.rb', line 19

def close = @queue.close

#default_portObject



18
# File 'lib/shmactor.rb', line 18

def default_port = @queue

#joinObject



21
22
23
24
# File 'lib/shmactor.rb', line 21

def join
  @thread.join
  self
end

#receiveObject



17
# File 'lib/shmactor.rb', line 17

def receive = @queue.receive

#sendObject



15
# File 'lib/shmactor.rb', line 15

def send(...) = self.<<(...)

#valueObject



26
27
28
29
30
# File 'lib/shmactor.rb', line 26

def value
  # Ractor seems to join when you call #value but Thread does not
  join
  @thread.value
end