How does the future works?
janckerchen opened this issue · comments
I dont understand invoke_on_rmt_process
, my understanding it is a async call to proccess in another thread, how the result returned immediately like sync?
#web/rmt_service.rb
put '/agents' do
agent_setting = load_body.map do |setting|
setting.each_with_object({}) { |pair, r| r[pair[0].to_sym] = pair[1] }
end
result = invoke_on_rmt_process do |_trading_context, _queue| <------here, why get result immediately
rmt.update_agent_setting(agent_setting)
end
ok(result)
end
invoke_on_rmt_process
executes the block by another thread and wait for the result.
I look around and found queue.pop is sync call, waiting something push in queue.