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.



63
64
65
66
67
68
69
70
71
72
# File 'lib/async/container/notify/server.rb', line 63

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



74
75
76
77
78
79
80
# File 'lib/async/container/notify/server.rb', line 74

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

#receiveObject



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

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