fastxpub/additional_sources/pre.js
function deferred() {
    var outResolve = function() {}; // will be overwritten
    var outReject = function() {}; // will be overwritten
    var promise = new Promise(function (resolve, reject) {
        outResolve = resolve;
        outReject = reject;
    });
    return {
        promise: promise,
        resolve: outResolve,
        reject: outReject,
    };
}
function deferred() {
    var outResolve = function() {}; // will be overwritten
    var outReject = function() {}; // will be overwritten
    var promise = new Promise(function (resolve, reject) {
        outResolve = resolve;
        outReject = reject;
    });
    return {
        promise: promise,
        resolve: outResolve,
        reject: outReject,
    };
}
helpful script for deferred promise