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

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

Overview

A bound context for receiving messages.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Context

Initialize the context with the given path.



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

def initialize(path)
  @path = path
  @bound = Addrinfo.unix(@path, ::Socket::SOCK_DGRAM).bind
  
  @state = {}
end

Instance Method Details

#closeObject

Close the bound context.



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

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

#receiveObject

Receive a message from the bound context.



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/async/container/notify/server.rb', line 100

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