private static async Task ExecuteRequestsAsync(
            ConcurrentDictionary <string, NetworkRequestCallback> queue,
            NetworkRequestCallback requestCallback,
            CancellationTokenSource cts)
        {
            if (cts.IsCancellationRequested)
            {
                queue.AddOrUpdate(
                    requestCallback.Request.Identifier.ToString(),
                    requestCallback,
                    (s, callback) => requestCallback);

                return;
            }

            NetworkRequest        request         = requestCallback.Request;
            WeakReferenceCallback successCallback = requestCallback.SuccessCallback;
            WeakReferenceCallback errorCallback   = requestCallback.ErrorCallback;

            try
            {
                object response = await request.ExecuteAsync(successCallback.Type);

                successCallback.Invoke(response);
            }
            catch (Exception ex)
            {
                successCallback.Invoke(Activator.CreateInstance(successCallback.Type));
                errorCallback.Invoke(ex);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NetworkRequestCallback"/> class.
 /// </summary>
 /// <param name="request">
 /// The network request.
 /// </param>
 /// <param name="successCallback">
 /// The success callback.
 /// </param>
 /// <param name="errorCallback">
 /// The error callback.
 /// </param>
 public NetworkRequestCallback(
     NetworkRequest request,
     WeakReferenceCallback successCallback,
     WeakReferenceCallback errorCallback)
 {
     this.Request         = request ?? throw new ArgumentNullException(nameof(request));
     this.SuccessCallback = successCallback;
     this.ErrorCallback   = errorCallback;
 }
        /// <inheritdoc />
        public void AddOrUpdate <TRequest, TResponse, TErrorResponse>(
            TRequest request,
            Action <TResponse> successCallback,
            Action <TErrorResponse> errorCallback) where TRequest : NetworkRequest
        {
            var weakSuccessCallback = new WeakReferenceCallback(successCallback, typeof(TResponse));
            var weakErrorCallback   = new WeakReferenceCallback(errorCallback, typeof(TErrorResponse));
            var requestCallback     = new NetworkRequestCallback(request, weakSuccessCallback, weakErrorCallback);

            this.CurrentQueue.AddOrUpdate(
                request.Identifier.ToString(),
                requestCallback,
                (s, callback) => requestCallback);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NetworkRequestCallback"/> class.
 /// </summary>
 /// <param name="request">
 /// The network request.
 /// </param>
 /// <param name="successCallback">
 /// The success callback.
 /// </param>
 public NetworkRequestCallback(NetworkRequest request, WeakReferenceCallback successCallback)
     : this(request, successCallback, null)
 {
 }