{"size": 1218, "ext": "js", "max_stars_repo_path": "src/services/svHttpBuffer.js", "max_stars_repo_name": "Relaymark/angular-es6-oauth2-code-flow", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/services/svHttpBuffer.js", "max_issues_repo_name": "Relaymark/angular-es6-oauth2-code-flow", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/services/svHttpBuffer.js", "max_forks_repo_name": "Relaymark/angular-es6-oauth2-code-flow", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.8823529412, "max_line_length": 80, "alphanum_fraction": 0.4893267652}
'use strict';
svHttpBuffer.$inject = ['$injector'];
export default function svHttpBuffer($injector) {

    var buffer = [];

    /** Service initialized later because of circular dependency problem. */
    var $http;

    var retryHttpRequest = function (config, deferred) {
        function successCallback(response) {
            deferred.resolve(response);
        }

        function errorCallback(response) {

            deferred.reject(response);
        }

        $http = $http || $injector.get('$http');
        $http(config).then(successCallback, errorCallback);
    };



    return {
        append(config, deferred) {
            buffer.push({
                config: config,
                deferred: deferred
            });
        },

            rejectAll(reason) {
            if (reason) {
                for (let i = 0; i < buffer.length; ++i) {
                    buffer[i].deferred.reject(reason);
                }
            }
            buffer = [];
        },

            retryAll(updater) {

            for (let i = 0; i < buffer.length; ++i) {
                retryHttpRequest(updater(buffer[i].config), buffer[i].deferred);
            }
            buffer = [];
        }
    };
}