Class: Async::Container::Notify::Server::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/async/container/notify/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Context

Returns a new instance of Context.



80
81
82
83
84
85
86
87
88
89
# File 'lib/async/container/notify/server.rb', line 80

def initialize(path)
  @path = path
  @endpoint = IO::Endpoint.unix(@path, ::Socket::SOCK_DGRAM)
  
  Sync do
    @bound = @endpoint.bind
  end
  
  @state = {}
end

Instance Method Details

#closeObject



91
92
93
94
95
96
97
# File 'lib/async/container/notify/server.rb', line 91

def close
  Sync do
    @bound.close
  end
  
  File.unlink(@path)
end

#receiveObject



99
100
101
102
103
104
105
106
107
# File 'lib/async/container/notify/server.rb', line 99

def receive
  while true
    data, _address, _flags, *_controls = @bound.recvmsg(MAXIMUM_MESSAGE_SIZE)
    
    message = Server.load(data)
    
    yield message
  end
end