How to use the when/node.lift 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 JamieMason / shrinkpack / test / e2e / test-util.js View on Github external
// node modules
var fs = require('fs');
var os = require('os');
var path = require('path');

// 3rd party modules
var execa = require('execa');
var when = require('when');
var whenNode = require('when/node');

// implementation
var mkdir = whenNode.lift(fs.mkdir);
var readFile = whenNode.lift(fs.readFile);
var rimraf = whenNode.lift(require('rimraf'));

// public
module.exports = {
  setNpmVersion: function (npmVersion) {
    return execa('npm', ['install', '-g', 'npm@' + npmVersion]);
  },
  getNpmVersion: function () {
    return execa.stdout('npm', ['-v']);
  },
  createTestApp: function (dirPath, packagePath) {
    return mkdir(dirPath).then(function () {
      return when.promise(function (res, rej) {
        var read = fs.createReadStream(packagePath);
        var write = fs.createWriteStream(path.join(dirPath, 'package.json'));
github LeanKit-Labs / seriate / src / sqlContextUtils.js View on Github external
function preparedSql( state, name, options ) {
	var cmd = new sql.PreparedStatement( state.transaction || state.connection );
	cmd.multiple = options.hasOwnProperty( "multiple" ) ? options.multiple : false;

	var params = createParameters( options.params );
	var paramKeyValues = {};

	params.forEach( function( param ) {
		cmd.input( param.key, param.type );
		paramKeyValues[ param.key ] = param.value;
	} );

	var prepare = lift( cmd.prepare ).bind( cmd );
	var execute = lift( cmd.execute ).bind( cmd );
	var unprepare = lift( cmd.unprepare ).bind( cmd );
	var statement = transformQuery( options.params, options.preparedSql );

	return instrument( state, name, function() {
		return prepare( statement )
			.then( function() {
				if ( options.stream ) {
					cmd.stream = true;

					// Can't use the lifted execute here because we need the
					// request returned by the original callback version, which the
					// lift would replace with a promise.
					var req = cmd.execute( paramKeyValues, _.noop );
					var stream = new DataResultStream( req );
					stream.on( "end", unprepare );
github LeanKit-Labs / seriate / src / sqlContextUtils.js View on Github external
function preparedSql( state, name, options ) {
	var cmd = new sql.PreparedStatement( state.transaction || state.connection );
	cmd.multiple = options.hasOwnProperty( "multiple" ) ? options.multiple : false;

	var params = createParameters( options.params );
	var paramKeyValues = {};

	params.forEach( function( param ) {
		cmd.input( param.key, param.type );
		paramKeyValues[ param.key ] = param.value;
	} );

	var prepare = lift( cmd.prepare ).bind( cmd );
	var execute = lift( cmd.execute ).bind( cmd );
	var unprepare = lift( cmd.unprepare ).bind( cmd );
	var statement = transformQuery( options.params, options.preparedSql );

	return instrument( state, name, function() {
		return prepare( statement )
			.then( function() {
				if ( options.stream ) {
					cmd.stream = true;

					// Can't use the lifted execute here because we need the
					// request returned by the original callback version, which the
					// lift would replace with a promise.
					var req = cmd.execute( paramKeyValues, _.noop );
					var stream = new DataResultStream( req );
					stream.on( "end", unprepare );
					return when.resolve( stream );
				}
github JamieMason / shrinkpack / src / lib / fs.js View on Github external
function wrap(fn) {
  return rateLimit(whenNode.lift(fn));
}
github mako-taco / DecorateThis / gulpfile.js View on Github external
gutil.log('Fatal error', err.stack);
		callback(err);
	}
});

startTestServer = nodefn.lift(function (callback) {
	gutil.log('Starting test server on port ' + process.env.NODE_PORT);
	server.start(process.env.NODE_PORT, callback);
});

stopTestServer = nodefn.lift(function (callback) {
	gutil.log('Stopping test server on port ' + process.env.NODE_PORT);
	server.stop(callback);
});

webpackRun = nodefn.lift(nodefn.lift(webpack));

gulp.task('test', ['build'], function (callback) {
	startTestServer()
		.then(function () {
			return runTests();
		}, notifyBuildFailed)
		.then(notifyTestsPassed, function (err) {
			process.exit(1);
			return notifyTestsFailed(err);
		})
		.ensure(function () {
			return stopTestServer();
		});
});

gulp.task('build', function (callback) {
github particle-iot / particle-cli / src / lib / cloud.js View on Github external
_readTrimBlankLinesAndComments(file) {
		const read = whenNode.lift(fs.readFile);
		return read(file).then(buf => {
			const lines = buf.toString().split('\n');
			return _.chain(lines)
				.map(l => l.trim())
				.compact()
				.filter(l => !l.match(/^#.*$/))
				.value();
		});
	},
github carrot / sprout / lib / template.js View on Github external
import which from 'which'
import path from 'path'
import yaml from 'js-yaml'
import minimatch from 'minimatch'
import lodash from 'lodash'
import Joi from 'joi'
import _rimraf from 'rimraf'
import _readdirp from 'readdirp'
import _fs from 'fs'
import _dns from 'dns'
import {exec as _exec} from 'child_process'
import {ncp as _ncp} from 'ncp'

const rimraf = node.lift(_rimraf)
const exec = node.lift(_exec)
const readdirp = node.lift(_readdirp)
const ncp = node.lift(_ncp)
const fs = node.liftAll(_fs, (pfs, lifted, name) => {
  pfs[`${name}Async`] = lifted
  return pfs
})
const dns = node.liftAll(_dns)

/*
 * Given a Sprout instance and a name, returns a Template instance.
 * @param {Function} sprout - Sprout instance.
 * @param {String} name - Name of template
 * @param {String} src (optional) - Path or URL to source. Only required for
 * `template.save`.
 * @return {Function} - Template instance.
 */
class Template {
github carrot / sprout / lib / utils.js View on Github external
import W from 'when'
import node from 'when/node'
import ejs from 'ejs'
import path from 'path'
import _ from 'lodash'
import underscoreString from 'underscore.string'
import _fs from 'fs'
import _mkdirp from 'mkdirp'
import {exec as _exec} from 'child_process'
import {ncp as _ncp} from 'ncp'

const fs = node.liftAll(_fs, (pfs, lifted, name) => {
  pfs[`${name}Async`] = lifted
  return pfs
})
const exec = node.lift(_exec)
const ncp = node.lift(_ncp)
const mkdirp = node.lift(_mkdirp)

/*
 * Given a source path and a target path, returns a Utils instance.
 * @param {String} src - The template source path.
 * @param {String} target - The template destination path.
 * @return {Function} - Template instance.
 */
const Utils = function (src, target) {
  /*
   * Copy a file from one path relative to the src, to another relative to the
   * target.
   * @param {String} from - the path to copy from, relative to the src.
   * @param {String} to - the path to copy to.
   * @return {Promise} - promise to copy
github carrot / sprout / lib / template.js View on Github external
import path from 'path'
import yaml from 'js-yaml'
import minimatch from 'minimatch'
import lodash from 'lodash'
import Joi from 'joi'
import _rimraf from 'rimraf'
import _readdirp from 'readdirp'
import _fs from 'fs'
import _dns from 'dns'
import {exec as _exec} from 'child_process'
import {ncp as _ncp} from 'ncp'

const rimraf = node.lift(_rimraf)
const exec = node.lift(_exec)
const readdirp = node.lift(_readdirp)
const ncp = node.lift(_ncp)
const fs = node.liftAll(_fs, (pfs, lifted, name) => {
  pfs[`${name}Async`] = lifted
  return pfs
})
const dns = node.liftAll(_dns)

/*
 * Given a Sprout instance and a name, returns a Template instance.
 * @param {Function} sprout - Sprout instance.
 * @param {String} name - Name of template
 * @param {String} src (optional) - Path or URL to source. Only required for
 * `template.save`.
 * @return {Function} - Template instance.
 */
class Template {
  constructor (_options) {