How to use deferred - 10 common examples

To help you get started, we’ve selected a few deferred 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 medikoo / fs2 / test / readdir.js View on Github external
/* eslint max-lines: off */

"use strict";

var push       = Array.prototype.push
  , fs         = require("fs")
  , pathUtils  = require("path")
  , aFrom      = require("es5-ext/array/from")
  , diff       = require("es5-ext/array/#/diff")
  , startsWith = require("es5-ext/string/#/starts-with")
  , deferred   = require("deferred")
  , delay      = deferred.delay
  , promisify  = deferred.promisify
  , mkdir      = promisify(fs.mkdir)
  , writeFile  = promisify(fs.writeFile)
  , unlink     = promisify(fs.unlink)
  , rmdir      = promisify(fs.rmdir)
  , basename   = pathUtils.basename
  , resolve    = pathUtils.resolve
  , sep        = pathUtils.sep
  , pgPath     = resolve(__dirname, "./__playground/readdir");

module.exports = function (t) {
	var pathsAll, paths2, paths0, files2, replaceSep, DELAY = 100;
	replaceSep = function (path) { return path.replace(/\//g, sep); };
	pathsAll = [
		"done", "done/done", "done/done/dthree", "done/done/dthree/dthree",
		"done/done/dthree/dthree/foo", "done/done/dthree/dtwo", "done/done/dthree/dtwo/foo",
github medikoo / fs2 / test / lib / find-root.js View on Github external
"use strict";

var fs        = require("fs")
  , deferred  = require("deferred")
  , resolve   = require("path").resolve
  , promisify = deferred.promisify
  , delay     = deferred.delay
  , mkdir     = promisify(fs.mkdir)
  , rmdir     = promisify(fs.rmdir)
  , gitMode   = require("../../lib/ignore-modes/git")
  , rootPath  = resolve(__dirname, "../__playground/lib/find-root");

module.exports = function (t, a, d) {
	var gitRoot = resolve(rootPath, ".git")
	  , onePath = resolve(rootPath, "one")
	  , gitOnePath = resolve(onePath, ".git")
	  , twoPath = resolve(onePath, "two")
	  , gitTwoPath = resolve(twoPath, ".git")
	  , filePath = resolve(twoPath, "file.xxx");

	var DELAY = 100, watcher, events = [];

	// Create /.git
github medikoo / modules-webmake / lib / parser.js View on Github external
resolveExternal(fromfile, fileDirname, scope, dep) {
		log.debug("resolve external %s", dep.value);
		const org = dep.value, lScope = scope;
		let filename = join(dep.value), tree, currentRequire, main, path, ext;

		const [name] = filename.split(sep, 1);
		return deferred.promisifySync(() => {
			// If already processed, return result
			if (this.modules[name]) return this.modules[name];

			if (name === "webmake") {
				this.packages.webmake = resolve(__dirname, "../");
				return (this.modules.webmake = {});
			}
			// Find path to package with Node.js internal functions
			currentRequire = getRequire(fromfile);
			try {
				path = main = currentRequire.resolve(name);
			} catch (e) {
				// No main module for the package, try full require path
				try {
					path = currentRequire.resolve(org);
				} catch (e2) {
github JamieMason / image-optimisation-tools-comparison / app.js View on Github external
'use strict';

// 3rd party modules
const childProcess = require('child_process');
const deferred = require('deferred');
const fs = require('fs');
const path = require('path');

const exec = deferred.promisify(childProcess.exec);
const execFile = deferred.promisify(childProcess.execFile);
const glob = deferred.promisify(require('glob'));

const stat = deferred.promisify(fs.stat);

// Implementation

async function start() {
  const imageNames = await getImageNames();
  const toolNames = await getToolNames();
  const total = imageNames.length * toolNames.length;
  let i = 1;
  const images = [];
  for (const imageName of imageNames) {
    let bestScore = 0;
    let highestSaving = 0;
    let leastLoss = 0;
github JamieMason / image-optimisation-tools-comparison / app.js View on Github external
'use strict';

// 3rd party modules
const childProcess = require('child_process');
const deferred = require('deferred');
const fs = require('fs');
const path = require('path');

const exec = deferred.promisify(childProcess.exec);
const execFile = deferred.promisify(childProcess.execFile);
const glob = deferred.promisify(require('glob'));

const stat = deferred.promisify(fs.stat);

// Implementation

async function start() {
  const imageNames = await getImageNames();
  const toolNames = await getToolNames();
  const total = imageNames.length * toolNames.length;
  let i = 1;
  const images = [];
  for (const imageName of imageNames) {
    let bestScore = 0;
    let highestSaving = 0;
github JamieMason / image-optimisation-tools-comparison / app.js View on Github external
'use strict';

// 3rd party modules
const childProcess = require('child_process');
const deferred = require('deferred');
const fs = require('fs');
const path = require('path');

const exec = deferred.promisify(childProcess.exec);
const execFile = deferred.promisify(childProcess.execFile);
const glob = deferred.promisify(require('glob'));

const stat = deferred.promisify(fs.stat);

// Implementation

async function start() {
  const imageNames = await getImageNames();
  const toolNames = await getToolNames();
  const total = imageNames.length * toolNames.length;
  let i = 1;
  const images = [];
  for (const imageName of imageNames) {
    let bestScore = 0;
    let highestSaving = 0;
    let leastLoss = 0;
    const image = {
github medikoo / dbjs / lib / types / ext / password.js View on Github external
// Must not be used on client-side.

'use strict';

var promisify = require('deferred').promisify
  , bcrypt    = require('bcrypt')
  , string    = require('../string')

  , genSalt = promisify(bcrypt.genSalt), hash = promisify(bcrypt.hash)
  , compare = promisify(bcrypt.compare);

module.exports = string.create('password', {
	async: true,
	min: 5,
	pattern: /(?=[\0-\uffff]*\d)(?=[\0-\uffff]*[a-zA-Z])/,
	rounds: 10,
	compare: function (password, hash) { return compare(password, hash); },
	validate: function (value) {
		return hash(string.validate.call(this, value), genSalt(this.rounds || 10));
	}
});
github shubik / prometheus_deprecated / lib / helpers / form_parser.js View on Github external
this._attributes[key] = (params[key].toLowerCase() === 'true') ? true : false;
                        break;

                    default:
                        this._attributes[key] = params[key];
                }

            } else {
                this._attributes[key] = this._schema[key].default;
            }
        }
    }

    /* --- Handle file uploads --- */

    deferred.map(files, _.bind(uploader, this))
    (function (result) {
        def.resolve(self);
    }, function(err) {
        def.resolve(err);
    });

    return def.promise;
}
github medikoo / fs2 / test / symlink.js View on Github external
"use strict";

var promisify = require("deferred").promisify
  , fs        = require("fs")
  , path      = require("path")
  , resolve   = path.resolve
  , lstat     = promisify(fs.lstat)
  , unlink    = promisify(fs.unlink)
  , rootPath  = resolve(__dirname, "./__playground/symlink")
  , base      = resolve(rootPath, "from")
  , regular   = resolve(rootPath, "foo")
  , deep      = resolve(rootPath, "foo/bar");

module.exports = function (t) {
	return {
		Regular: {
			Success: function (a, d) {
				t(base, regular)(function () {
					return lstat(regular)(function (stats) {
						a(stats.isSymbolicLink(), true);
						return unlink(regular);
					});
				}).done(d, d);
github medikoo / modules-webmake / test / index.js View on Github external
""(t, a, d) {
		const input = `${ pg }/lib/program.js`
		    , output = `${ pg }/build.js`
		    , options = { include: `${ pg }/lib/included`, ignore: [resolve(pg, "not-taken.js")] };
		t = promisify(t);
		t(input, options)(result => {
			const program = runInNewContext(result, {});
			a(program.x.name, "x", "Same path require");
			a(program.x.getZ().name, "z", "Deferred call");
			a(
				program.x.getZ(), program.x.getZ(),
				"Requiring same object twice, should return same object"
			);
			a(program.y.z.name, "z", "Require within required module");
			a(program.y.z.y.name, "y", "Circular dependency");
			a(program.dirjs, "DIR.JS", "Directory with '.js' extension");
			a(program.indexed.name, "indexed", "Folder index");
			a(program.included.a.name, "included.a", "Manually included #1");
			a(program.included.b.name, "included.b", "Manually included #2");
			a(program.outer.name, "outer", "Require module up tree");
			a(program.outerSubIndex.name, "outer-index", "Require index from sibling directory");

deferred

Modular and fast Promises implementation

ISC
Latest version published 5 years ago

Package Health Score

65 / 100
Full package analysis