How to use the infusion.promise function in infusion

To help you get started, we’ve selected a few infusion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GPII / universal / scripts / copyUninstrumentedCode.js View on Github external
promises.push(function () {
            var wrappedPromise = fluid.promise();
            var src  = path.resolve(resolvedSrcRoot, dirToCopy);
            var dest = path.resolve(resolvedTargetRoot, dirToCopy);
            var rawPromise = copy(src, dest);
            /* eslint dot-notation: "off" */
            rawPromise.then(wrappedPromise.resolve).catch(wrappedPromise.reject);
        });
    });
github GPII / universal / gpii / node_modules / preferencesServer / src / preferencesServer.js View on Github external
gpii.preferencesServer.createPreferences = function (preferencesService, ontologyHandler, preferences, view, gpiiKey) {
    fluid.log("gpii.preferencesServer.createPreferences called for creating preferences: ", preferences);
    var promiseTogo = fluid.promise();
    if (!preferences) {
        // preferences must be provided
        fluid.log("Preferences Server, createPreferences(), creating preferences, rejected due to missing preferences");
        promiseTogo.reject(gpii.preferencesServer.errors.missingPreferences);
    } else {
        var payload = {};
        payload[view] = preferences;

        fluid.log("Preferences Server, createPreferences(), creating GPII key (", gpiiKey, ") and its preferences: ", payload);
        var mapper = function (addPrefsResponse) {
            return fluid.extend({}, addPrefsResponse, {
                preferences: fluid.get(addPrefsResponse, ["preferences", view])
            });
        };
        promiseTogo = fluid.promise.map(preferencesService.createPreferences(payload, gpiiKey), mapper);
    }
github GPII / universal / gpii / node_modules / flowManager / src / SolutionsRegistryDataSource.js View on Github external
gpii.flowManager.solutionsRegistry.dataSource.handle = function (that, requestOptions) {
    var promise = fluid.promise();
    if (requestOptions.os) { // if "os" is defined, return only solution registry entries for that OS
        if (requestOptions.os in that.fullSolutionsRegistry) {
            promise.resolve(that.fullSolutionsRegistry[requestOptions.os]);
        } else {
            promise.reject({
                isError: true,
                message: "The requested OS (" + requestOptions.os + ") was not present in the solutions registry",
                statusCode: 404
            });
        }
    } else { // if no "os" is requested, return the full solutions registry
        promise.resolve(that.fullSolutionsRegistry);
    }
    return promise;
};
github GPII / universal / gpii / node_modules / lifecycleManager / src / UserLogonStateChange.js View on Github external
gpii.lifecycleManager.untrusted.getSettings = function (settingsDataSource, gpiiKey, deviceReporterData, onMatchDone, onError) {
    // Unnecessary to fetch settings for "noUser" from the cloud
    var noUserSettings = {
        gpiiKey: "noUser",
        preferences: {},
        matchMakerOutput: {
            inferredConfiguration: {
                "gpii-default": {
                    applications: {}
                }
            },
            lifecycleInstructions: {}
        }
    };

    var settings = gpiiKey === "noUser" ? fluid.promise().resolve(noUserSettings) : settingsDataSource.get(gpiiKey, deviceReporterData);

    settings.then(onMatchDone.fire, onError.fire);
};
github GPII / universal / gpii / node_modules / userListeners / src / pcsc.js View on Github external
gpii.userListeners.pcsc.authenticateBlock = function (card, block) {

    var authRequired = false;
    if (card.authenticate) {
        // Mifare: Only need to authenticate once per sector - When a block is authenticated, the other blocks in the
        // sector are also accessible.
        var sectorSize = 4;
        var sector = Math.floor(block / sectorSize);
        card.authed = card.authed || {};
        authRequired = !card.authed[sector];
        card.authed[sector] = true;
    }

    var promise = fluid.promise();
    if (authRequired) {
        // There are two keys (0 and 1), and there are two types of key (TYPE A or B). Try each one until it successful.
        var typeA = 0x60,
            typeB = 0x61;
        var keys = [
            { type: typeA, number: 0 },
            { type: typeB, number: 0 },
            { type: typeA, number: 1 },
            { type: typeB, number: 1 }
        ];

        // Try each key until successful.
        var tryKey = function (keyIndex, attempt) {
            keyIndex = keyIndex % keys.length;
            gpii.userListeners.pcsc.loadAuthenticationKeys(card, block, keys[keyIndex].type, keys[keyIndex].number)
                .then(function () {
github GPII / universal / gpii / node_modules / preferencesServer / src / preferencesServer.js View on Github external
gpii.preferencesServer.createPreferences = function (preferencesService, ontologyHandler, preferences, view, gpiiKey) {
    fluid.log("gpii.preferencesServer.createPreferences called for creating preferences: ", preferences);
    var promiseTogo = fluid.promise();
    if (!preferences) {
        // preferences must be provided
        fluid.log("Preferences Server, createPreferences(), creating preferences, rejected due to missing preferences");
        promiseTogo.reject(gpii.preferencesServer.errors.missingPreferences);
    } else {
        var payload = {};
        payload[view] = preferences;

        fluid.log("Preferences Server, createPreferences(), creating GPII key (", gpiiKey, ") and its preferences: ", payload);
        var mapper = function (addPrefsResponse) {
            return fluid.extend({}, addPrefsResponse, {
                preferences: fluid.get(addPrefsResponse, ["preferences", view])
            });
        };
        promiseTogo = fluid.promise.map(preferencesService.createPreferences(payload, gpiiKey), mapper);
    }
github GPII / universal / gpii / node_modules / userListeners / src / pcsc.js View on Github external
gpii.userListeners.pcsc.readBytes = function (card, length) {
    var promise = fluid.promise();
    var sequence = [];
    card.nextBlock = card.startBlock;

    for (var bytes = 0, block = 0; bytes < length; bytes += card.blockLength, block++) {
        sequence.push(gpii.userListeners.pcsc.readNextBlock);
    }

    fluid.promise.sequence(sequence, card).then(function (result) {
        var allData = Buffer.concat(result);
        promise.resolve(allData);
    }, promise.reject);

    return promise;
};
github GPII / universal / gpii / node_modules / flowManager / src / MatchMaking.js View on Github external
gpii.flowManager.getPreferences = function (that, prefsServerDataSource) {
        var gpiiKey = that.gpiiKey;
        if (gpiiKey !== "noUser") {
            fluid.log("gpii.flowManager.getPreferences called - fetching preferences from URL " + prefsServerDataSource.options.prefsServerURL);
        }

        var noUserPrefs = {};
        var promise = gpiiKey === "noUser" ? fluid.promise().resolve(noUserPrefs) : prefsServerDataSource.get(gpiiKey);
        promise.then(function (data) {
            that.events.onPreferences.fire(data.preferences || data);
        }, function (err) {
            that.events.onError.fire({
                isError: true,
                message: "Error when retrieving preferences: " + err.message,
                statusCode: 404
            });
        });
    };
github GPII / universal / scripts / deleteAndLoadSnapsets.js View on Github external
gpii.dataLoader.configureStep = function (details, options) {
    var togo = fluid.promise();
    var response = gpii.dataLoader.createResponseHandler(
        details.responseDataHandler,
        options,
        togo,
        details.responseErrMsg
    );
    var request;
    if (details.dataToPost) {
        request = gpii.dataLoader.createPostRequest(
            details.dataToPost, response, options
        );
    } else {
        request = gpii.dataLoader.queryDatabase(
            details.requestUrl, response, details.requestErrMsg
        );
    }
github GPII / universal / gpii / node_modules / settingsHandlers / src / RemoteFileSettingsHandler.js View on Github external
gpii.settingsHandlers.remoteFileSettingsHandler.setImpl = function (payload) {
    var promiseTogo = fluid.promise();

    var results = {};
    var promises = [];
    fluid.each(payload.settings, function (settingValue, key) {
        if (settingValue) {
            var value = settingValue.value || settingValue;

            var settingPromise = fluid.promise();
            promises.push(settingPromise);
            settingPromise.then(null, function (reason) {
                fluid.fail("remoteFileSettingsHandler failed for setting '" + key + "' in payload ", payload, reason);
            });

            var options = payload.options.settings[key];

            var remoteFileDownload = gpii.settingsHandlers.remoteFileDownload({