A couple days ago I created this Angular 1.x provider for my Ionic/Cordova app. I'm using webpack and babel-loader for ES6/ES2015 syntax and modules.All my provider does is provide an alternative to ES6/ES2015's Promise.all and Angular's $q.all(), making sure every promise is completed (i.e. resolved or rejected) and the result promise won't resolve/reject until that. The final promise rejects if (at the end of the process) any of the original promises failed, and resolves otherwise.In both cases (resolved, rejected) the callbacks (passed to the .then() method of the result promise) will receive as a parameter an array of objects, representing the state and results/errors of all the original promises.The progress notification gives back the completion percentage. The intermediate notification gives back a promise that has just been resolved/rejected. Both also return the partial array of all the results. That's useful when you want to display information to the user as soon as possible.ReviewI would like general feedback and improvements, in particular about the ES6 usage, Angular best practices, and the naming of the service, its variables and code reusability + readability.Is it correct my use of $q.defer()? I wasn't sure how to handle the notification/progress without it.I tried to integrate with the ES6 features and OOP (if it makes sense to talk about OOP in Angular at all MVVM), so I used a class, and I'm registering the provider and injecting the dependencies in the class constructor using an injects parameter and Function.prototype.bind().service/promise_combine.jsexport default class PromiseCombine {    constructor(        injects = {},        promises = []    ) {        let {$q, $timeout} = injects;        let deferred = $q.defer();        let {resolve, reject, notify} = deferred;        $timeout(() => {            this._combine({                resolve,                reject,                notify            }, promises);        }, 0);        return deferred.promise;    }    _combine(methods, promises) {        let {resolve, reject, notify} = methods;        let failed = false;        let results = new Array(promises.length);        let rescount = 0;        promises.forEach((value, key) => {            value.then(result => {                results[key] = {                    status: resolved,                    resolved: true,                    rejected: false,                    error: null,                    result                };                notify({                    type: intermediate,                    intermediate: true,                    progress: false,                    percentage: null,                    index: key,                    data: results[key],                    partial: results                });            }, error => {                failed = true;                results[key] = {                    status: rejected,                    resolved: false,                    rejected: true,                    result: null,                    error                };                notify({                    type: intermediate,                    intermediate: true,                    progress: false,                    percentage: null,                    index: key,                    data: results[key],                    partial: results                });            }).finally(() => {                rescount += 1;                notify({                    type: progress,                    progress: true,                    intermediate: false,                    percentage: rescount / promises.length,                    index: null,                    data: null,                    partial: results                });                if (rescount === promises.length) {                    // ALL DONE                    if (failed) {                        reject(results);                    } else {                        resolve(results);                    }                }            });        });    }}services.jsimport angular from angular;import PromiseCombine from ./service/promise_combine;let ngmodule = angular.module(app.services, []);console.info(Registering provider: PromiseCombine);ngmodule.provider(PromiseCombine, function PromiseCombineProvider() {    this.$get = [$q, $timeout, ($q, $timeout) => PromiseCombine.bind(this, {        $q,        $timeout    })];});Example Usageexample.jsimport angular from angular;angular.module(app, [app.services]).controller(myCtrl, PromiseCombine => {    let promises = []    // Populate promises array [...]    let combined = new PromiseCombine(promises);    combined.then(success => {        // All OK, process data (optionally filter that)    }, error => {        // Something failed, process data anyway (optionally filter that)    });});
Bill has a hard time keeping all his promises
javascript;angular.js;promise;ecmascript 6