【发布时间】:2016-05-03 11:33:32
【问题描述】:
这在 Rails 中没有记录,但 ActionCable 有一个名为 PeriodicTimers 的模块
https://github.com/rails/rails/blob/master/actioncable/lib/action_cable/channel/periodic_timers.rb
现在在我的app/channels/requests_channel.rb 中,我尝试通过以下方式进行测试:
class RequestsChannel < ApplicationCable::Channel
periodically :transmit_status, every: 2.seconds
def subscribed
stream_from "requests_#{current_user.id}"
end
def unsubscribed
end
private
def transmit_status
puts "ping"
end
end
当我连接并订阅流时,控制台中没有显示任何内容。我觉得 ActionCable 中的代码相当简单,这应该可以工作,但我无法让它工作。有人有这方面的经验吗?
【问题讨论】:
-
我已经研究了几个小时,试图理解为什么这不起作用。我也想设置定期定时器。