def get_long_running_operation_result(azure_response, custom_deserialization_block, final_state_via = FinalStateVia::DEFAULT)
      check_for_status_code_failure(azure_response)

      http_method = azure_response.request.method

      polling_state = PollingState.new(azure_response, @long_running_operation_retry_timeout)
      request = azure_response.request

      if !AsyncOperationStatus.is_terminal_status(polling_state.status)
        task = Concurrent::TimerTask.new do
          begin
            if !polling_state.azure_async_operation_header_link.nil?
              update_state_from_azure_async_operation_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri, user_agent_extended: user_agent_extended), polling_state)
            elsif !polling_state.location_header_link.nil?
              update_state_from_location_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri, user_agent_extended: user_agent_extended), polling_state, custom_deserialization_block, final_state_via)
            elsif http_method === :put
              get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, {query_params: request.query_params, headers: request.headers, user_agent_extended: user_agent_extended})
              update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block)
            else
              task.shutdown
              if final_state_via == FinalStateVia::LOCATION
                if !polling_state.response.body.to_s.empty?
                  body = JSON.load(polling_state.response.body)
                  polling_state.resource = custom_deserialization_block.call(body)
                else
                  fail AzureOperationError, 'Location header is missing from long running operation'
                end
              else
                fail AzureOperationError, 'Location header is missing from long running operation'
              end
            end

            if AsyncOperationStatus.is_terminal_status(polling_state.status)
              task.shutdown
            end
          rescue Exception => e
            task.shutdown
            e
          end
        end

        polling_delay = polling_state.get_delay
        polling_delay = 0.1 if polling_delay.nil? || polling_delay == 0

        task.execution_interval = polling_delay
        task.execute
        task.wait_for_termination

        polling_error = task.value
        fail polling_error if polling_error.is_a?(Exception)
      end

      if AsyncOperationStatus.is_successful_status(polling_state.status)
        # Process long-running PUT/PATCH
        if (http_method === :put || http_method === :patch) && polling_state.resource.nil?
          get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, {query_params: request.query_params, headers: request.headers})
          update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block)
        end

        if final_state_via == FinalStateVia::LOCATION
          if((http_method === :post || http_method === :delete) && !polling_state.location_header_link.nil?)
            update_state_from_location_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri, user_agent_extended: user_agent_extended), polling_state, custom_deserialization_block, final_state_via)
          end
        end

        # Process long-running POST/DELETE operation with schema defined on success status codes
        if (http_method === :post || http_method === :delete) && custom_deserialization_block && polling_state.response
          unless polling_state.response.body.to_s.empty?
            body = JSON.load(polling_state.response.body)
            polling_state.resource = custom_deserialization_block.call(body)
          end
        end
      end

      if AsyncOperationStatus.is_failed_status(polling_state.status)
        fail polling_state.get_operation_error
      end

      polling_state.get_operation_response
    end
def get_long_running_operation_result(azure_response, custom_deserialization_block, final_state_via = FinalStateVia::DEFAULT)
      check_for_status_code_failure(azure_response)

      http_method = azure_response.request.method

      polling_state = PollingState.new(azure_response, @long_running_operation_retry_timeout)
      request = azure_response.request

      if !AsyncOperationStatus.is_terminal_status(polling_state.status)
        task = Concurrent::TimerTask.new do
          begin
            if !polling_state.azure_async_operation_header_link.nil?
              update_state_from_azure_async_operation_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri, user_agent_extended: user_agent_extended), polling_state)
            elsif !polling_state.location_header_link.nil?
              update_state_from_location_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri, user_agent_extended: user_agent_extended), polling_state, custom_deserialization_block, final_state_via)
            elsif http_method === :put
              get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, {query_params: request.query_params, headers: request.headers, user_agent_extended: user_agent_extended})
              update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block)
            else
              task.shutdown
              if final_state_via == FinalStateVia::LOCATION
                if !polling_state.response.body.to_s.empty?
                  body = JSON.load(polling_state.response.body)
                  polling_state.resource = custom_deserialization_block.call(body)
                else
                  fail AzureOperationError, 'Location header is missing from long running operation'
                end
              else
                fail AzureOperationError, 'Location header is missing from long running operation'
              end
            end

            if AsyncOperationStatus.is_terminal_status(polling_state.status)
              task.shutdown
            end
          rescue Exception => e
            task.shutdown
            e
          end
        end

        polling_delay = polling_state.get_delay
        polling_delay = 0.1 if polling_delay.nil? || polling_delay == 0

        task.execution_interval = polling_delay
        task.execute
        task.wait_for_termination

        polling_error = task.value
        fail polling_error if polling_error.is_a?(Exception)
      end

      if AsyncOperationStatus.is_successful_status(polling_state.status)
        # Process long-running PUT/PATCH
        if (http_method === :put || http_method === :patch) && polling_state.resource.nil?
          get_request = MsRest::HttpOperationRequest.new(request.base_uri, request.build_path.to_s, :get, {query_params: request.query_params, headers: request.headers})
          update_state_from_get_resource_operation(get_request, polling_state, custom_deserialization_block)
        end

        if final_state_via == FinalStateVia::LOCATION
          if((http_method === :post || http_method === :delete) && !polling_state.location_header_link.nil?)
            update_state_from_location_header(polling_state.get_request(headers: request.headers, base_uri: request.base_uri, user_agent_extended: user_agent_extended), polling_state, custom_deserialization_block, final_state_via)
          end
        end

        # Process long-running POST/DELETE operation with schema defined on success status codes
        if (http_method === :post || http_method === :delete) && custom_deserialization_block && polling_state.response
          unless polling_state.response.body.to_s.empty?
            body = JSON.load(polling_state.response.body)
            polling_state.resource = custom_deserialization_block.call(body)
          end
        end
      end

      if AsyncOperationStatus.is_failed_status(polling_state.status)
        fail polling_state.get_operation_error
      end

      polling_state.get_operation_response
    end
Retrieves the result of 'POST','DELETE','PUT' or 'PATCH' operation. Performs polling of required.
 @param azure_response [MsRestAzure::AzureOperationResponse] response from Azure service.
 @param custom_deserialization_block [Proc] custom logic for response deserialization.
 @param final_state_via [MsRestAzure::FinalStateVia] Final State via value

 @return [MsRest::HttpOperationResponse] the response.