unageanu / jiji2

Forex algorithmic trading framework using OANDA REST API.

Home Page:http://jiji2.unageanu.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

https://github.com/unageanu/jiji2/blob/e1b5c6316e3c222b77d3c87b7b21a4098ae2d2d2/src/jiji/web/services/abstract_service.rb

I look around and found queue.pop is sync call, waiting something push in queue.