How to use the es6-promise.Promise function in es6-promise

To help you get started, we’ve selected a few es6-promise 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 pavelfeldman / node-devtools / debug_target.js View on Github external
DebugTarget.prototype.sendCommand = function(command, args) {
  // Construct packet object.
  var packet = {
    'seq': ++this.nextTargetSeqId_,
    'type': 'request',
    'command': command
  };
  if (args) {
    packet['arguments'] = args;
  }

  // Stash promise.
  var promise = new Promise((function(resolve, reject) {
    this.pendingTargetPromises_[packet['seq']] = {
      resolve: resolve,
      reject: reject
    };
  }).bind(this));

  // Send the data.
  var packetString = JSON.stringify(packet);
  var packetLength = packetString.length;
  this.targetSocket_.write(
      'Content-Length: ' + packetLength + '\r\n\r\n' +
      packetString);

  if (this.argv_['log-network']) {
    console.log('[->V8]', packetString);
  }
github buzinas / tslint-eslint-rules / src / readme / index.ts View on Github external
function updateRuleFile(name: string, rule: IRule): Promise {
  const baseUrl = 'https://github.com/buzinas/tslint-eslint-rules/blob/master';
  const docFileName = `src/docs/rules/${name}Rule.md`;
  return new Promise((fulfill, reject) => {
    fs.readFile(docFileName, 'utf8', (readErr, data) => {
      rule.tslintUrl = rule.tslintUrl || `${baseUrl}/${docFileName}`;
      let content = readErr || !data ? '' : data;
      content = content.replace(
        /^$/gm,
        [
          '\n',
          createRuleContent(rule),
          '\n' + (readErr ? '\n' : '')
        ].join('')
      );
      fs.writeFile(docFileName, content, { encoding: 'utf8' }, (writeErr) => {
        if (writeErr) {
          return reject(writeErr);
        }
        console.log(` - ${name}`);
github christianalfoni / EmptyBox / server / core / articles.js View on Github external
var readArticles = function(dir) {
  return new Promise(function(resolve, reject) {
    fs.readdir(dir, function(err, files) {
      if (err) {
        console.error('Error loading articles', err);
      }
      resolve(files.map(function (file) {
        return {
          path: dir,
          filename: file
        };
      }));
    });
  });
};
github smartive / proc-that / helpers / Buffer.ts View on Github external
public read():Promise {
        if (!this.isEmpty) {
            let content = this.content.shift();
            this.emit('release', content);

            if (this.isEmpty) {
                this.emit('empty');
                if (this.sealed) this.emit('end');
            }

            return Promise.resolve(content);
        }

        return new Promise(resolve => {
            this.once('write', () => resolve(this.read()));
        });
    }
github kazu69 / domain-info / index.js View on Github external
function getWhoisDomain(domain, server, port) {
    if(!domain) throw new Error('`domain` is required');
    if(!server) throw new Error('`server` is required');

    const socket = new net.Socket();
    const encoding = 'utf8'
    if(!port) { port = 43 }
    let responseText = '';

    return new Promise((resolve, reject) => {
        socket.setEncoding(encoding);

        socket.connect(port, server, () => {
            socket.end(domain + '\r\n', encoding);
        });

        socket.on('data', data => {
            resolve(data);
        });

        socket.on('error', error => {
            reject(error);
        });
    });
}
github flashphoner / flashphoner_client / src / temasys-media-provider.js View on Github external
var getScreenDeviceId = function (constraints) {
    return new Promise(function (resolve, reject) {
        var o = {};
        if (window.chrome) {
            chrome.runtime.sendMessage(extensionId, {type: "isInstalled"}, function (response) {
                if (response) {
                    o.maxWidth = constraints.video.width;
                    o.maxHeight = constraints.video.height;
                    o.maxFrameRate = constraints.video.frameRate.max;
                    o.chromeMediaSource = "desktop";
                    chrome.runtime.sendMessage(extensionId, {type: "getSourceId"}, function (response) {
                        if (response.error) {
                            reject(new Error("Screen access denied"));
                        } else {
                            o.chromeMediaSourceId = response.sourceId;
                            resolve({mandatory: o});
                        }
                    });
github borisdiakur / memoize-fs / index.js View on Github external
function invalidateCache (cacheId) {
    return new Promise(function (resolve, reject) {
      if (cacheId && typeof cacheId !== 'string') {
        reject(Error('cacheId option of type string expected, got \'' + typeof cacheId + '\''))
      } else {
        var cachPath = cacheId ? path.join(options.cachePath, cacheId) : options.cachePath
        rmdir(cachPath, function (err) {
          if (err) {
            reject(err)
          } else {
            resolve()
          }
        })
      }
    })
  }
github peter-mouland / web-caddy / tasks / init.js View on Github external
function askForGitRepo(gitRepo){
    return new Promise(function(resolve){
        if (gitRepo && gitRepo.length>0) resolve(gitRepo);
        prompt.start();
        prompt.get([{
            description: 'GitHub Repository URL'.bgBlack.white + ' (leave blank if none)'.bgBlack.white.dim,
            name: 'repo',
            default: git.checkRemote() || ''
        }], function(err, result) {
            if (!result) return resolve('');
            resolve(git.validRepo(result.repo));
        });
    });
}
github tanhauhau / express-pdf / spec / index.spec.js View on Github external
app.get('/test/3', function(req, res){
            var promise = res.pdf(path.resolve(__dirname, './fixture/test.pdf'));

            expect(promise).not.toBeUndefined();
            expect(promise).toEqual(jasmine.any(Promise));
            promise.then(function(){
                expect(true).toEqual(true);
                finish();
            }, function(){
                expect('should not call catch').toBe(true);
                finish();
            });
        });
        server = app.listen(8888);
github buzinas / tslint-eslint-rules / dist / readme / fetch.js View on Github external
function compareToTSLint() {
    return new es6_promise_1.Promise(function (fulfill) {
        requestFromGithub('/repos/palantir/tslint/contents/src/rules', function (data) {
            var rules = data
                .filter(function (obj) { return obj.name.endsWith('.ts'); })
                .map(function (obj) { return obj.name.substring(0, obj.name.length - 7); });
            var notInUse = require('../../src/readme/unusedTSLintRules.json');
            notInUse.forEach(function (name) {
                var camel = rules_1.toCamelCase(name);
                var index = rules.indexOf(camel);
                if (index > -1) {
                    rules.splice(index, 1);
                }
            });
            var tsRules = Object.keys(rules_1.ruleTSMap);
            var missing = arrayDiff(rules, tsRules);
            var buffer = [];
            if (missing.length) {