Class: Bran::LibUV::Reactor::Collections::Abstract
- Inherits:
-
Object
- Object
- Bran::LibUV::Reactor::Collections::Abstract
show all
- Defined in:
- lib/bran/libuv/reactor/collections.rb
Instance Method Summary
collapse
Constructor Details
#initialize(reactor) ⇒ Abstract
Returns a new instance of Abstract.
8
9
10
11
12
13
14
|
# File 'lib/bran/libuv/reactor/collections.rb', line 8
def initialize(reactor)
@reactor = reactor
@idents_by_addr = {}
@items_by_ident = {}
@stacks_by_ident = {}
end
|
Instance Method Details
#drop_item(ident, item) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/bran/libuv/reactor/collections.rb', line 95
def drop_item(ident, item)
concrete_stop_item(ident, item)
concrete_release_item(item)
nil
end
|
#invoke_by_addr(addr, rc = 0) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/bran/libuv/reactor/collections.rb', line 58
def invoke_by_addr(addr, rc = 0)
ident = @idents_by_addr[addr]
return unless ident
stack = @stacks_by_ident.fetch(ident)
handler, persistent = stack.last
pop ident unless persistent
invoke_handler(handler, rc)
end
|
#invoke_by_ident(ident, rc = 0) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/bran/libuv/reactor/collections.rb', line 48
def invoke_by_ident(ident, rc = 0)
stack = @stacks_by_ident[ident]
return unless ident
handler, persistent = stack.last
pop ident unless persistent
invoke_handler(handler, rc)
end
|
#invoke_handler(handler, rc = 0) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/bran/libuv/reactor/collections.rb', line 70
def invoke_handler(handler, rc = 0)
case handler
when ::Fiber
if rc == 0
handler.resume nil
else
handler.resume Util.error_create("running the libuv loop", rc)
end
when ::Proc
if rc == 0
handler.call nil
else
error = Util.error_create("running the libuv loop", rc)
handler.call error
end
end
end
|
#item_by_ident(ident) ⇒ Object
44
45
46
|
# File 'lib/bran/libuv/reactor/collections.rb', line 44
def item_by_ident(ident)
@items_by_ident[ident]
end
|
#make_item(ident, extra_args) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/bran/libuv/reactor/collections.rb', line 88
def make_item(ident, )
item = concrete_alloc_item
concrete_start_item(ident, item, *)
item
end
|
#pop(ident) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/bran/libuv/reactor/collections.rb', line 30
def pop(ident)
stack = @stacks_by_ident[ident]
return unless stack
stack.pop
return unless stack.empty?
@stacks_by_ident.delete(ident)
item = @items_by_ident.delete(ident)
@idents_by_addr.delete(item.address)
drop_item(ident, item)
end
|
#push(ident, handler, persistent, *extra_args) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/bran/libuv/reactor/collections.rb', line 16
def push(ident, handler, persistent, *)
if (stack = @stacks_by_ident[ident])
stack << [handler, persistent]
else
item = make_item(ident, )
@items_by_ident[ident] = item
@idents_by_addr[item.address] = ident
@stacks_by_ident[ident] = [[handler, persistent]]
end
ident
end
|