在Rails 5开发模式下,代码更改和刷新后,它触发重新加载程序中间件卸载/重新加载类。但是,在重新加载程序完成重新加载之前,请求将移至下一个中间件。
重新加载器包装有执行器,并且不包含executor.rb。似乎在var tValue = {"cat": "4" , "dog": "5", "fish": "9" };
var tList = [];
for(var tKey in tValue) tList.push({name: tKey, value: tValue[tKey]});
console.log(tList);
之后和run!
之前调用了下一个中间件,它与以下日志消息保持一致。我想知道是否可以确保仅在完成重新加载后才调用下一个中间件。
我尝试用complete!
,Rails.application.executor.wrap
和Rails.application.reloader.wrap
包装cusstomMiddle调用,但结果不起作用。
Rails版本:5.1
Ruby版本:2.4.1
我添加了以下日志消息,查看事件的顺序。
application.rb
ActiveSupport::Dependencies.interlock.permit_concurrent_loads
custom_middleware.rb
ActiveSupport::Reloader.before_class_unload do
puts "Before class unload, Thread Id: #{Thread.current.object_id}"
end
ActiveSupport::Reloader.after_class_unload do
puts "After class unload, Thread Id: #{Thread.current.object_id}"
end
ActiveSupport::Reloader.to_run do
puts "Reloading, Thread Id: #{Thread.current.object_id}"
end
ActiveSupport::Reloader.to_complete do
puts "DONE Reloading, Thread Id: #{Thread.current.object_id}"
end
以下是我得到的输出,并注意到在“完成重载”之前调用了“调用自定义中间件”
def call(env)
puts "Call custom middleware, Thread Id: #{Thread.current.object_id}"
@app.call(env)
end
我所有的中间件
Started GET "/" for 127.0.0.1 at 2018-07-06 01:59:54 -0500
Before class unload, Thread Id: 70134855012820
After class unload, Thread Id: 70134855012820
Reloading, Thread Id: 70134855012820
Call custom middleware, Thread Id: 70134855012820
Processing by HomeController#index as HTML
Rendering home/index.html.erb
Rendered home/index.html.erb (0.3ms)
Completed 200 OK in 17ms (Views: 13.5ms)
DONE Reloading, Thread Id: 70134855012820