How to use the when.resolve function in when

To help you get started, we’ve selected a few when 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 EdgeVerve / oe-cloud / lib / db-storage-for-node-red.js View on Github external
saveLibraryEntry: function saveLibraryEntryFn(type, path, meta, body) {
    if (settings.readOnly) {
      return when.resolve();
    }
    var fn = fspath.join(libDir, type, path);
    var headers = '';
    for (var i in meta) {
      if (meta.hasOwnProperty(i)) {
        headers += '// ' + i + ': ' + meta[i] + '\n';
      }
    }
    return promiseDir(fspath.dirname(fn)).then(function promiseDirFn() {
      writeFile(fn, headers + body);
    });
  }
};
github rkaw92 / esdf / Saga.v2.js View on Github external
Saga.prototype.processEvent = function processEvent(event, commit){
	var self = this;
	// Guard clause: do not process duplicate events.
	if(this._seenEventIDs[event.eventID]){
		return when.resolve();
	}
	// Gather all transitions that are to occur. We use each transition's supplied decision function.
	var transitionIntents = [];
	for(var transitionKey in this._currentStage.transitions){
		var currentTransition = this._currentStage.transitions[transitionKey];
		var transitionDecision = currentTransition.eventEndsTransition(event, commit, this._enqueuedEvents, this._stageAccumulator);
		if(transitionDecision){
			transitionIntents.push(currentTransition);
		}
	}
	// Check if any transitions have been marked for passing.
	if(transitionIntents.length > 0){
		// There is at least one nominated transition.
		// Check for conflicts.
		if(transitionIntents.length > 1){
			//TODO: define the event payload below in a better way.
github LeanKit-Labs / seriate / src / sqlContextUtils.js View on Github external
table.columns.add( columnName, column.type, { nullable: column.nullable === undefined ? true : column.nullable } );
	} );

	var columnNames = Object.keys( options.bulkLoadTable.columns );

	options.bulkLoadTable.rows.forEach( function( row ) {
		var values = columnNames.map( function( columnName ) {
			return row[ columnName ];
		} );

		table.rows.add.apply( table.rows, values );
	} );

	var req = new sql.Request( state.transaction || state.connection );

	return when.resolve()
	.then( function() {
		if ( !isTempTableName( options.bulkLoadTable.name ) ) {
			return;
		}

		var dropSql = "IF OBJECT_ID('tempdb.." + options.bulkLoadTable.name + "') IS NOT NULL DROP TABLE " + options.bulkLoadTable.name + ";";

		if ( !options.bulkLoadTable.useExisting ) {
			// Make sure we're not adding to an existing temp table
			nonPreparedSql( state, name + "-pre-drop", { query: dropSql } );
		}

		// Accumulate list of tables on state, which is the transaction object, to enforce appropriate scope
		// Keep this list to avoid double-dropping tables when we bulk load the same temp table more than once using `useExisting`
		state.droppedTempTables = state.droppedTempTables || {};
github node-red / node-red / red / runtime-registry / library.js View on Github external
files.forEach(function(file) {
                var fullPath = fspath.join(path,file);
                var stats = fs.lstatSync(fullPath);
                if (stats.isDirectory()) {
                    validFiles.push(file);
                    promises.push(getFlowsFromPath(fullPath));
                } else if (/\.json$/.test(file)){
                    validFiles.push(file);
                    promises.push(when.resolve(file.split(".")[0]))
                }
            })
            var i=0;
github graydon / stxt / src / store.js View on Github external
put: function(kind, key, val) {
        var kx = this.get_kind(kind);
        kx[key] = val;
        return when.resolve(null);
    },
    del: function(kind, key) {
github futurestudio / hapi-rethinkdb-dash / server / user-login-signup / handler.js View on Github external
return user.comparePassword(payload.password).then(function (isMatch) {
          return isMatch ? Promise.resolve(user) : Promise.reject('Password not correct')
        })
      }).then(function (user) {
github brandoncarl / taskco / lib / tasks.js View on Github external
return getNextId.then(function(id) {
                    var task = new Task(factory, id, type, data, options);
                    return when.resolve(task);
                   });
}
github particle-iot / spark-cli / commands / CloudCommands.js View on Github external
devices.forEach(function (device) {
					if (!device.id) {
						return;
					}

					if (device.connected) {
						promises.push(api.getAttributes(device.id).then(function(attrs) {
							return extend(device, attrs);
						}));
					}
					else {
						promises.push(when.resolve(device));
					}
				});
github cambecc / earth / server / oscar-update.js View on Github external
function extractLayers(product) {
    var productPath = path.join(opt.gridHome, product.name);
    if (!fs.existsSync(productPath)) {
        log.info("product file not found, skipping: " + productPath);
        return when.resolve([]);
    }
    var layers = LAYER_RECIPES.map(function(recipe) {
        var tempPath = createTempSync({suffix: ".json"});
        var args = util.format("%s %s -o %s %s", GRIB2JSON_FLAGS, recipe.filter, tempPath, productPath);
        return tool.grib2json(args, process.stdout, process.stderr).then(function(returnCode) {
            if (returnCode !== 0) {
                log.info(util.format("grib2json failed (%s): %s", returnCode, productPath));
                return when.reject(returnCode);
            }
            log.info("processing: " + tempPath);
            var processed = processLayer(recipe, tempPath);
            var layer = processed.layer, layerPath = layer.path(opt.layerHome);
            mkdirp.sync(layer.dir(opt.layerHome));
            fs.writeFileSync(layerPath, JSON.stringify(processed.data, null, INDENT), {encoding: "utf8"});
            log.info("successfully built: " + layerPath);
            return layer;
github cobyism / ghost-on-heroku / core / server / models / user.js View on Github external
function validatePasswordLength(password) {
    try {
        if (!validator.isLength(password, 8)) {
            throw new Error('Your password must be at least 8 characters long.');
        }
    } catch (error) {
        return when.reject(error);
    }
    return when.resolve();
}