Returns both a promise and the spawned process so that it can be killed if needed.
12269
function spawnExt(command, args, options, ignoreClose = false,
                  printMessage = msg => process.stdout.write(msg)) {
  let proc;
  const promise = new Promise((resolve, reject) => {
    let descr = command + ' ' + args.join(' ');
    let processOutput = '';
    printMessage(`running: ${descr}\n`);
    try {
      proc = xSpawn.spawn(command, args, options);
    } catch (e) {
      console.log(e);
      reject(e);
      return {proc: null, promise};
    }
    proc.stdout.on('data', printMessage);
    proc.stderr.on('data', printMessage);

    proc.on('close', function(returnCode) {
      printMessage(`completed: ${descr}\n\n`);
      // Many tasks (e.g., tsc) complete but are actually errors;
      // Confirm return code is zero.
      returnCode === 0 || ignoreClose ? resolve(0) : reject(returnCode);
    });
    proc.on('error', function(data) {
      printMessage(`completed with error: ${descr}\n\n`);
      printMessage(`${data.toString()}\n`);
      reject(data);
    });
  });
  return {proc, promise};
}
591391
function triggerPromise() {
        var me = this;
        var args = arguments;

        var canHandlePromise =
            this.children.indexOf("completed") >= 0 &&
            this.children.indexOf("failed") >= 0;

        var createdPromise = new PromiseFactory(function(resolve, reject) {
            // If `listenAndPromise` is listening
            // patch `promise` w/ context-loaded resolve/reject
            if (me.willCallPromise) {
                _.nextTick(function() {
                    var previousPromise = me.promise;
                    me.promise = function (inputPromise) {
                        inputPromise.then(resolve, reject);
                        // Back to your regularly schedule programming.
                        me.promise = previousPromise;
                        return me.promise.apply(me, arguments);
                    };
                    me.trigger.apply(me, args);
                });
                return;
            }

            if (canHandlePromise) {
                var removeSuccess = me.completed.listen(function () {
                    var args = Array.prototype.slice.call(arguments);
                    removeSuccess();
                    removeFailed();
                    resolve(args.length > 1 ? args : args[0]);
                });

                var removeFailed = me.failed.listen(function () {
                    var args = Array.prototype.slice.call(arguments);
                    removeSuccess();
                    removeFailed();
                    reject(args.length > 1 ? args : args[0]);
                });
            }

            _.nextTick(function () {
                me.trigger.apply(me, args);
            });

            if (!canHandlePromise) {
                resolve();
            }
        });

        // Ensure that the promise does trigger "Uncaught (in promise)" errors in console if no error handler is added
        // See: https://github.com/reflux/reflux-promise/issues/4
        createdPromise.catch(function() {});

        return createdPromise;
    }
1239779
function promiseWrapper (resolve, reject) {
            // Wait for the process to exit
            process.on ("exit", (code) => {
                // Did the process crash?
                if (code !== 0) reject (process.stderr.textContent);

                // Resolve
                resolve (process.stdout.textContent);
            });

            // Pipe the script into stdin and end
            process.stdin.write (script);
            process.stdin.end ();
        }
789152
function (promise) {
            var targets = this._targets;
            targets.push(promise);
            promise['catch'](
                function() {
                    return true;
                }
            ).then(
                function() {
                    targets.splice(targets.indexOf(promise), 1);
                }
            );
            return Notifier.decorate(promise);
        }
76744
function promiseCommand(command) {
    const opts = {
        env: process.env
    };
    console.log('>>>>', command)
    return spawnShell(command, opts).exitPromise
        .then((exitCode) => {
            if (exitCode === 0) {
                return;
            } else {
                throw Error("Exit " + exitCode)
            }
        })
}
841258
function() {
        return new Promise(function(resolve, reject) {
            exec("find . ! -name '" + __filename.split('/').pop() + "' -iname '*\.js' | xargs grep 'CRUD.Entity.call(this);' -isl", {
                timeout: 3000,
                cwd: process.cwd()
            }, function(err, stdout, stdin) {
                var results = stdout.trim().split('\n');
                var entities = {};

                // iterate all found js files and search for CRUD.define calls
                results.map(function(filename) {
                    if (filename.trim() == '') return;
                    var code = fs.readFileSync(filename) + '';
                    var ast = UglifyJS.parse(code);
                    ast.walk(new UglifyJS.TreeWalker(function(node) {
                        if (node instanceof UglifyJS.AST_Call && node.start.value == 'CRUD' && node.expression.property == 'define') {
                            entities[node.args[0].start.value] = filename;
                        }
                    }));
                });

                resolve(entities);
            });
        });
    }
549086
async function stop () {
    return new Promise(function (resolve, reject) {
        // if not server then resolve
        if (!immutableApp || !immutableApp.server || !immutableApp.started) {
            resolve()
        }
        // close server
        immutableApp.server.close(function (err) {
            if (err) {
                reject(err)
            }
            else {
                // clear server
                immutableApp.server = undefined
                immutableApp.started = false
                // resolve
                resolve()
            }
        })
    })
}
152616
def spawn_process(self, target, *args):
        
        p = Process(target=target, args=args)
        p.daemon = True
        if target == worker:
            p.daemon = Conf.DAEMONIZE_WORKERS
            p.timer = args[2]
            self.pool.append(p)
        p.start()
        return p
1368646
function (promise) {
            promise.success = promise.done;
            promise.error = promise.fail;
            promise.complete = promise.always;
            return promise;
        }
1119036
function init(options){

    return Promise.resolve()
      .then(function() {

        if(!_.get(parameters,'process.source')){
          return;
        }

        return Promise.resolve()
          .then(function() {
            return updateAllKeys(options);
          })
          .then(function() {
            return createMissingFolders(options);
          })
          .then(function() {
            return deleteUnused(options);
          })
          .then(function() {
            return deleteEmptyFolders(options);
          });

      })
      .then(function() {

        if(!_.get(parameters,'process.search')){
          return;
        }

        return require('./search')(util,options);

      })
      .then(function() {
        util.log('Sync is complete');
      });

  }
1022184
function exec(cmd, args = [], silent = false) {
    return __awaiter(this, void 0, void 0, function* () {
        const response = [];
        return new Promise((resolve, reject) => {
            const exe = child_process_1.spawn(cmd, args, {
                env: process.env
            });
            exe.stdout.on('data', data => {
                response.push(data.toString());
                if (!silent) {
                    console.log(data.toString());
                }
            });
            exe.stderr.on('data', data => {
                if (!silent) {
                    console.error(data.toString());
                }
            });
            exe.on('exit', code => {
                if (code === 0) {
                    return resolve(response);
                }
                else {
                    if (!silent) {
                        console.error('Problem executing ' + cmd);
                    }
                    return reject();
                }
            });
        });
    });
}
1023579
function spawn($gen) {
		$send  = array($gen, 'send');
		$throw = array($gen, 'throw');
		$run = function($fn, $in) use ($gen, $send, $throw, &$run) {
			try {
				while (true) {
					$val = Promise::interpret( $fn ? $fn($in) : $gen->current() );
					if ( ! $gen->valid() ) { $this->resolve( $fn == $throw ? null : $in); return; }
					if ( ! $val instanceof PromiseInterface ) {
						$fn = $send;  $in = $val;
					} else if ( $val->getState() === PromiseInterface::REJECTED ) {
						$fn = $throw; $in = GP\exception_for( GP\inspect($val)['reason'] );
					} else {
						$val->then(
							function($val) use($run, $send)  { $run( $send, $val ); },
							function($err) use($run, $throw) { $run( $throw, GP\exception_for($err) ); }
						);
						return;
					}
				}
			} catch (\Exception $e) {
				$this->reject($e);
			} catch (\Throwable $t) {
				$this->reject($t);
			}
		};
		if ( $gen instanceof \Generator ) {
			$run( null, null );
		} else {
			$this->resolve($gen);
		}
		if ( $this->getState() === PromiseInterface::FULFILLED )
			return $this->wait();
		return $this;
	}
1149303
function(signal)
    {
        return new Promise( resolve =>
        {
            for (let uniqueID in cluster.workers)
            {
                if (cluster.workers.hasOwnProperty(uniqueID))
                {
                    const worker = cluster.workers[uniqueID];

                    worker.kill(signal);
                }
            }

            resolve();
        });
    }
960848
function (version, args, pipe) {
        let spawnOpts = { cwd: ForestInternal.elmRoot(version) };
        let buffers = [];
        return new Promise((resolve, reject) => {
            let child = child_process_1.spawn('npm', args, spawnOpts);
            if (pipe) {
                child.stdout.pipe(process.stdout);
                child.stderr.pipe(process.stderr);
                process.stdin.pipe(child.stdin);
                process.stdin.resume();
            }
            child.stdout.on('data', (data) => {
                buffers.push(data);
            });
            child.on('close', (code) => {
                if (pipe) {
                    process.stdin.pause();
                    process.stdin.unpipe();
                }
                if (code === 0) {
                    let str = Buffer.concat(buffers).toString('utf-8');
                    return resolve(str);
                }
                // Use reject instead of throw here because we are in a callback
                reject(new ForestError(Errors.NpmCommandFailed, `npm command failed with exit code ${code}`, code));
            });
        }).catch((err) => {
            if (err instanceof ForestError) {
                throw err;
            }
            else {
                throw new ForestError(Errors.NpmRunFailed, err);
            }
        });
    }
717757
function streamify(promise, factory) {
  var _then = promise.then;
  promise.then = function() {
    factory();
    var newPromise = _then.apply(promise, arguments);
    return streamify(newPromise, factory);
  };
  promise.stream = factory;
  return promise;
}
1353679
function PromiseFactory() {
	var deferred = whenjs.defer();
	//var timeout = setTimeout(function () { console.log(t, 'Promise timed out')}, 3000);

	this.reject = function (err) {
		deferred.reject(err);
	};
	this.resolve = function (val) {
	//	clearTimeout(timeout);
		deferred.resolve(val);
	};
	this.promise = function () {
		return deferred.promise;
	};
}
580858
function _singlePromise () {
  let  done, cancel;
  const x = new Promise ( (resolve, reject ) => { 
                                                  done   = resolve
                                                  cancel = reject
                                 })

   return { 
               promise    : x
             , done       : done 
             , cancel     : cancel
             , onComplete : _after(x)
           }
   }