Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4769fc4b
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,发现更多精彩内容 >>
提交
4769fc4b
编写于
4月 14, 2016
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #24540 from sgrif/sg-actioncable-callbacks
Run Action Cable callbacks through the worker pool
上级
91798c75
d1766ef5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
5 deletion
+30
-5
actioncable/lib/action_cable/channel/streams.rb
actioncable/lib/action_cable/channel/streams.rb
+5
-2
actioncable/test/channel/stream_test.rb
actioncable/test/channel/stream_test.rb
+25
-3
未找到文件。
actioncable/lib/action_cable/channel/streams.rb
浏览文件 @
4769fc4b
...
...
@@ -76,8 +76,11 @@ def stream_from(broadcasting, callback = nil, coder: nil, &block)
# Don't send the confirmation until pubsub#subscribe is successful
defer_subscription_confirmation!
if
handler
=
callback
||
block
handler
=
->
message
{
handler
.
(
coder
.
decode
(
message
))
}
if
coder
if
user_handler
=
callback
||
block
user_handler
=
->
message
{
handler
.
(
coder
.
decode
(
message
))
}
if
coder
handler
=
->
message
do
connection
.
worker_pool
.
async_invoke
(
user_handler
,
:call
,
message
)
end
else
handler
=
default_stream_handler
(
broadcasting
,
coder:
coder
)
end
...
...
actioncable/test/channel/stream_test.rb
浏览文件 @
4769fc4b
...
...
@@ -116,11 +116,22 @@ class StreamTest < ActionCable::TestCase
require
'action_cable/subscription_adapter/inline'
class
UserCallbackChannel
<
ActionCable
::
Channel
::
Base
def
subscribed
stream_from
:channel
do
Thread
.
current
[
:ran_callback
]
=
true
end
end
end
class
StreamEncodingTest
<
ActionCable
::
TestCase
setup
do
@server
=
TestServer
.
new
(
subscription_adapter:
ActionCable
::
SubscriptionAdapter
::
Inline
)
@server
.
config
.
allowed_request_origins
=
%w( http://rubyonrails.com )
@server
.
stubs
(
:channel_classes
).
returns
(
ChatChannel
.
name
=>
ChatChannel
)
@server
.
stubs
(
:channel_classes
).
returns
(
ChatChannel
.
name
=>
ChatChannel
,
UserCallbackChannel
.
name
=>
UserCallbackChannel
,
)
end
test
'custom encoder'
do
...
...
@@ -134,6 +145,17 @@ class StreamEncodingTest < ActionCable::TestCase
end
end
test
"user supplied callbacks are run through the worker pool"
do
run_in_eventmachine
do
connection
=
open_connection
receive
(
connection
,
command:
'subscribe'
,
channel:
UserCallbackChannel
.
name
,
identifiers:
{
id:
1
})
@server
.
broadcast
'channel'
,
{}
wait_for_async
refute
Thread
.
current
[
:ran_callback
],
"User callback was not run through the worker pool"
end
end
private
def
subscribe_to
(
connection
,
identifiers
:)
receive
connection
,
command:
'subscribe'
,
identifiers:
identifiers
...
...
@@ -151,8 +173,8 @@ def open_connection
end
end
def
receive
(
connection
,
command
:,
identifiers
:)
identifier
=
JSON
.
generate
(
channel:
'ActionCable::StreamTests::ChatChannel'
,
**
identifiers
)
def
receive
(
connection
,
command
:,
identifiers
:
,
channel:
'ActionCable::StreamTests::ChatChannel'
)
identifier
=
JSON
.
generate
(
channel:
channel
,
**
identifiers
)
connection
.
dispatch_websocket_message
JSON
.
generate
(
command:
command
,
identifier:
identifier
)
wait_for_async
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录