Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dccc15d4
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dccc15d4
编写于
1月 22, 2016
作者:
M
Matthew Draper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split internal subscriber tracking from Postgres adapter
上级
83d2c39d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
70 addition
and
24 deletion
+70
-24
actioncable/lib/action_cable/subscription_adapter.rb
actioncable/lib/action_cable/subscription_adapter.rb
+4
-1
actioncable/lib/action_cable/subscription_adapter/postgresql.rb
...cable/lib/action_cable/subscription_adapter/postgresql.rb
+13
-23
actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb
...e/lib/action_cable/subscription_adapter/subscriber_map.rb
+53
-0
未找到文件。
actioncable/lib/action_cable/subscription_adapter.rb
浏览文件 @
dccc15d4
module
ActionCable
module
ActionCable
module
SubscriptionAdapter
module
SubscriptionAdapter
autoload
:Base
,
'action_cable/subscription_adapter/base'
extend
ActiveSupport
::
Autoload
autoload
:Base
autoload
:SubscriberMap
end
end
end
end
actioncable/lib/action_cable/subscription_adapter/postgresql.rb
浏览文件 @
dccc15d4
...
@@ -12,11 +12,11 @@ def broadcast(channel, payload)
...
@@ -12,11 +12,11 @@ def broadcast(channel, payload)
end
end
def
subscribe
(
channel
,
callback
,
success_callback
=
nil
)
def
subscribe
(
channel
,
callback
,
success_callback
=
nil
)
listener
.
subscribe_to
(
channel
,
callback
,
success_callback
)
listener
.
add_subscriber
(
channel
,
callback
,
success_callback
)
end
end
def
unsubscribe
(
channel
,
callback
)
def
unsubscribe
(
channel
,
callback
)
listener
.
unsubscribe_from
(
channel
,
callback
)
listener
.
remove_subscriber
(
channel
,
callback
)
end
end
def
with_connection
(
&
block
)
# :nodoc:
def
with_connection
(
&
block
)
# :nodoc:
...
@@ -36,11 +36,11 @@ def listener
...
@@ -36,11 +36,11 @@ def listener
@listener
||=
Listener
.
new
(
self
)
@listener
||=
Listener
.
new
(
self
)
end
end
class
Listener
class
Listener
<
SubscriberMap
def
initialize
(
adapter
)
def
initialize
(
adapter
)
super
()
@adapter
=
adapter
@adapter
=
adapter
@subscribers
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
[]
}
@sync
=
Mutex
.
new
@queue
=
Queue
.
new
@queue
=
Queue
.
new
Thread
.
new
do
Thread
.
new
do
...
@@ -65,32 +65,22 @@ def listen
...
@@ -65,32 +65,22 @@ def listen
end
end
pg_conn
.
wait_for_notify
(
1
)
do
|
chan
,
pid
,
message
|
pg_conn
.
wait_for_notify
(
1
)
do
|
chan
,
pid
,
message
|
@subscribers
[
chan
].
each
do
|
callback
|
broadcast
(
chan
,
message
)
::
EM
.
next_tick
{
callback
.
call
(
message
)
}
end
end
end
end
end
end
end
end
end
def
subscribe_to
(
channel
,
callback
,
success_callback
)
def
add_channel
(
channel
,
on_success
)
@sync
.
synchronize
do
@queue
.
push
([
:listen
,
channel
,
on_success
])
if
@subscribers
[
channel
].
empty?
@queue
.
push
([
:listen
,
channel
,
success_callback
])
end
@subscribers
[
channel
]
<<
callback
end
end
end
def
unsubscribe_from
(
channel
,
callback
)
def
remove_channel
(
channel
)
@
sync
.
synchronize
do
@
queue
.
push
([
:unlisten
,
channel
])
@subscribers
[
channel
].
delete
(
callback
)
end
if
@subscribers
[
channel
].
empty?
def
invoke_callback
(
*
)
@queue
.
push
([
:unlisten
,
channel
])
::
EM
.
next_tick
{
super
}
end
end
end
end
end
end
end
end
...
...
actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb
0 → 100644
浏览文件 @
dccc15d4
module
ActionCable
module
SubscriptionAdapter
class
SubscriberMap
def
initialize
@subscribers
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
[]
}
@sync
=
Mutex
.
new
end
def
add_subscriber
(
channel
,
subscriber
,
on_success
)
@sync
.
synchronize
do
new_channel
=
!
@subscribers
.
key?
(
channel
)
@subscribers
[
channel
]
<<
subscriber
if
new_channel
add_channel
channel
,
on_success
elsif
on_success
on_success
.
call
end
end
end
def
remove_subscriber
(
channel
,
subscriber
)
@sync
.
synchronize
do
@subscribers
[
channel
].
delete
(
subscriber
)
if
@subscribers
[
channel
].
empty?
@subscribers
.
delete
channel
remove_channel
channel
end
end
end
def
broadcast
(
channel
,
message
)
list
=
@sync
.
synchronize
{
@subscribers
[
channel
].
dup
}
list
.
each
do
|
subscriber
|
invoke_callback
(
subscriber
,
message
)
end
end
def
add_channel
(
channel
,
on_success
)
on_success
.
call
if
on_success
end
def
remove_channel
(
channel
)
end
def
invoke_callback
(
callback
,
message
)
callback
.
call
message
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录