anchor.diff:      end.
   
   
  +%% delegation_loop/1
  +%% ====================================================================
  +%% @doc Loop that is evaluated by socket process while it has spawned a handling process
  +%% and is delegating tasks.
  +%% @end
  +-spec delegation_loop(HandlerPid :: pid()) -> term().
  +%% ====================================================================
   delegation_loop(HandlerPid) ->
       receive
           {result, Result} ->
  
positive.code: %% Internal functions
  %% ====================================================================
  
  spawn_handling_process() ->
      SocketPid = self(),
      MsgID = 0, %% This can be 0 as one socket process sends only one request
      gen_server:call(?Dispatcher_Name, {node_chosen, {control_panel, 1, SocketPid, MsgID, {spawn_handler, SocketPid}}}),
      receive
          {worker_answer, MsgID, Resp} ->
              set_handler_pid(Resp)
      after 5000 ->
          ?error("Cannot spawn handling process, timeout"),
          {error, timeout}
      end.
  
  
  terminate_handling_process() ->
      get_handler_pid() ! terminate.
  
  
  delegate(Fun, Args) ->
      HandlerModule = get_handler_module(),
      case get_delegation() of
  
negative.code:     end.
  
  
  %% set_handler_module/1
  %% ====================================================================
  %% @doc Convenience function that stores the reference to handler module in process dict.
  %% @end
  -spec set_handler_module(Module :: atom()) -> term().
  %% ====================================================================
  set_handler_module(Module) ->
      erlang:put(handler_module, Module).
  
  
  %% get_handler_module/0
  %% ====================================================================
  %% @doc Convenience function that retrieves the reference to handler module from process dict.
  %% @end
  -spec get_handler_module() -> atom().
  %% ====================================================================
  get_handler_module() ->
      erlang:get(handler_module).
  
  
  %% set_handler_pid/1
  %% ====================================================================
  %% @doc Convenience function that stores the reference to handler pid in process dict.
  %% @end
  -spec set_handler_pid(Pid :: pid()) -> term().
  %% ====================================================================
  set_handler_pid(Pid) ->
      erlang:put(handler_pid, Pid).
  
  
  %% get_handler_pid/0
  %% ====================================================================
  %% @doc Convenience function that retrieves the reference to handler pid from process dict.
  %% @end
  -spec get_handler_pid() -> pid().
  %% ====================================================================
  get_handler_pid() ->
      erlang:get(handler_pid).
  
  
  %% set_delegation/1
  %% ====================================================================
  %% @doc Convenience function that stores the delegation flag in process dict.
  %% @end
  -spec set_delegation(Delegation :: boolean()) -> term().
  %% ====================================================================
  set_delegation(Delegation) ->
      erlang:put(delegation, Delegation).
  
  
  %% get_delegation/0
  %% ====================================================================
  %% @doc Convenience function that retrieves the delegation flag from process dict.
  %% @end
  -spec get_delegation() -> boolean().
  %% ====================================================================
  get_delegation() ->
      erlang:get(delegation).