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.


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

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

Instance Method Details

#closeObject


69
70
71
72
73
74
75
# File 'lib/async/debug/selector.rb', line 69

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

#deregister(monitor) ⇒ Object


57
58
59
60
61
62
63
# File 'lib/async/debug/selector.rb', line 57

def deregister(monitor)
	Async.logger.debug(self) {"Deregistering #{monitor.inspect}."}
	
	unless @monitors.delete?(monitor)
		raise RuntimeError, "Trying to remove monitor for #{monitor.inspect} but it was not registered!"
	end
end

#register(object, interests) ⇒ Object


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

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
	
	monitor = Monitor.new(@selector.register(object, interests), self)
	
	@monitors.add(monitor)
	
	return monitor
end

#select(*arguments) ⇒ Object


77
78
79
# File 'lib/async/debug/selector.rb', line 77

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

#wakeupObject


65
66
67
# File 'lib/async/debug/selector.rb', line 65

def wakeup
	@selector.wakeup
end