Class: Async::Debug::ReactorView

Inherits:
Live::View
  • Object
show all
Defined in:
lib/async/debug/reactor_view.rb

Instance Method Summary collapse

Constructor Details

#initialize(id, **data) ⇒ ReactorView

Returns a new instance of ReactorView.



28
29
30
31
32
33
# File 'lib/async/debug/reactor_view.rb', line 28

def initialize(id, **data)
	super
	
	@update = nil
	@top = Async::Task.current.reactor
end

Instance Method Details

#bind(page) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/async/debug/reactor_view.rb', line 35

def bind(page)
	super(page)
	
	@update = Async do |task|
		while true
			task.sleep(1.0/10.0)
			self.replace!
		end
	end
end

#closeObject



46
47
48
49
50
# File 'lib/async/debug/reactor_view.rb', line 46

def close
	@update.stop
	
	super
end

#handle(event, details) ⇒ Object



52
53
54
# File 'lib/async/debug/reactor_view.rb', line 52

def handle(event, details)
	replace!
end

#render(builder) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/async/debug/reactor_view.rb', line 90

def render(builder)
	builder.tag :div, class: 'tree' do
		builder.tag :ul do
			builder.inline :li do
				render_node(builder)
			end
		end
	end
end

#render_node(builder, node = @top) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/async/debug/reactor_view.rb', line 56

def render_node(builder, node = @top)
	klass = []
	title = []
	
	if node.respond_to?(:status)
		klass << node.status
	end
	
	if node.transient?
		klass << "transient"
	end
	
	if node.respond_to?(:backtrace)
		if backtrace = node.backtrace
			title = backtrace.first(8)
		end
	end
	
	builder.inline :span, class: klass.join(' '), title: title.join("\n") do
		text = node.annotation || "#{node.class} 0x#{node.object_id.to_s(16)}"
		builder.text(text)
	end
	
	if node.children
		builder.tag :ul do
			node.children.each do |child|
				builder.inline :li do
					render_node(builder, child)
				end
			end
		end
	end
end