Class: Async::Debug::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/async/debug/selector.rb

Instance Method Summary collapse

Constructor Details

#initialize(selector = NIO::Selector.new) ⇒ Selector

Returns a new instance of Selector.



37
38
39
40
# File 'lib/async/debug/selector.rb', line 37

def initialize(selector = NIO::Selector.new)
	@selector = selector
	@monitors = {}
end

Instance Method Details

#closeObject



76
77
78
79
80
81
82
# File 'lib/async/debug/selector.rb', line 76

def close
	if @monitors.any?
		raise LeakError, @monitors.values
	end
ensure
	@selector.close
end

#deregister(object) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/async/debug/selector.rb', line 60

def deregister(object)
	Async.logger.debug(self) {"Deregistering #{object.inspect}."}
	
	unless io = ::IO.try_convert(object)
		raise RuntimeError, "Could not convert #{io} into IO!"
	end
	
	unless @monitors.delete(io.fileno)
		raise RuntimeError, "Trying to remove monitor for #{io.inspect} but it was not registered!"
	end
end

#register(object, interests) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/async/debug/selector.rb', line 42

def register(object, interests)
	Async.logger.debug(self) {"Registering #{object.inspect} for #{interests}."}
	
	unless io = ::IO.try_convert(object)
		raise RuntimeError, "Could not convert #{io} into IO!"
	end
	
	if monitor = @monitors[io.fileno]
		raise RuntimeError, "Trying to register monitor for #{object.inspect} but it was already registered: #{monitor.inspect}!"
	end
	
	monitor = Monitor.new(@selector.register(object, interests), self)
	
	@monitors[io.fileno] = monitor
	
	return monitor
end

#select(*arguments) ⇒ Object



84
85
86
# File 'lib/async/debug/selector.rb', line 84

def select(*arguments)
	@selector.select(*arguments)
end

#wakeupObject



72
73
74
# File 'lib/async/debug/selector.rb', line 72

def wakeup
	@selector.wakeup
end