當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Q.Promise函數代碼示例

本文整理匯總了TypeScript中Q.Promise函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript Promise函數的具體用法?TypeScript Promise怎麽用?TypeScript Promise使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Promise函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: openConnections

 async openConnections() {
   for (let i = 0, len = this.httpServers.length; i < len; i++) {
     const httpServer = this.httpServers[i].http;
     const isListening = this.listenings[i];
     if (!isListening) {
       const netInterface = this.interfaces[i].ip;
       const port = this.interfaces[i].port;
       try {
         await Q.Promise((resolve:any, reject:any) => {
           // Weird the need of such a hack to catch an exception...
           httpServer.errorPropagates = function(err:any) {
             reject(err);
           };
           //httpServer.on('listening', resolve.bind(this, httpServer));
           httpServer.listen(port, netInterface, (err:any) => {
             if (err) return reject(err);
             this.listenings[i] = true;
             resolve(httpServer);
           });
         });
         this.logger && this.logger.info(this.name + ' listening on http://' + (netInterface.match(/:/) ? '[' + netInterface + ']' : netInterface) + ':' + port);
       } catch (e) {
         this.logger && this.logger.warn('Could NOT listen to http://' + netInterface + ':' + port);
         this.logger && this.logger.warn(e);
       }
     }
   }
   return [];
 }
開發者ID:Kalmac,項目名稱:duniter,代碼行數:29,代碼來源:network.ts

示例2: runFilenameOrFn_

export function runFilenameOrFn_(configDir: string, filenameOrFn: any, args?: any[]): Promise<any> {
  return Promise((resolvePromise) => {
    if (filenameOrFn && !(typeof filenameOrFn === 'string' || typeof filenameOrFn === 'function')) {
      throw new Error('filenameOrFn must be a string or function');
    }

    if (typeof filenameOrFn === 'string') {
      filenameOrFn = require(resolve(configDir, filenameOrFn));
    }
    if (typeof filenameOrFn === 'function') {
      let results = when(filenameOrFn.apply(null, args), null, (err) => {
        if (typeof err === 'string') {
          err = new Error(err);
        } else {
          err = err as Error;
          if (!err.stack) {
            err.stack = new Error().stack;
          }
        }
        err.stack = exports.filterStackTrace(err.stack);
        throw err;
      });
      resolvePromise(results);
    } else {
      resolvePromise(undefined);
    }
  });
}
開發者ID:JesseChezenko-AI,項目名稱:protractor,代碼行數:28,代碼來源:util.ts

示例3: start

 start(imageName, opts?: IStartDockerOpts, command?: string) {
     return Q.Promise((resolve, reject) => {
         let containerName = (opts && opts.name) ? opts.name : imageName;
         this.runWithoutDebugOnce(this.status(containerName)).then(
             (status) => {
                 if (!status) {
                     info(`Creating and starting container ${containerName}...`);
                     let c = `docker run -d`;
                     if (!opts) opts = {};
                     c = addOpts(c, opts);
                     // set sinsible defaults
                     if (!opts.name) c = addOpt(c, '--name', containerName);
                     c += ` ${imageName}`;
                     if (command) c += ` ${command}`;
                     run(c, this._debug).then(() => { resolve(true); }, reject);
                 } else if (status.indexOf('Up') == 1) {
                     info(`Container ${containerName} already started.`);
                     resolve(false)
                 } else if (status.indexOf('Exited') == 1) {
                     info(`Container ${containerName} exists but is not started. Starting now.`);
                     runWithoutDebug(`docker start ${containerName}`).then(
                         () => { resolve(true) },
                         reject
                     );
                 } else {
                     reject(`Could not start container ${containerName()}. Status was ${status} Should never hit this.`);
                 }
             },
             reject
         );
     });
 }
開發者ID:mattklein999,項目名稱:docker-cmd-js,代碼行數:32,代碼來源:container.ts

示例4: execute

    export function execute(grunt:IGrunt, options: GruntOptions, host: GruntHost): Q.Promise<any>{

        host.io.verbose("--task.execute");
        host.io.verbose("  options: " + JSON.stringify(options));

        return Q.Promise((resolve: (val: any) => void, reject: (val: any) => void, notify: (val: any) => void) => {

            if(options.gWatch){
                watch(grunt, options, host);
            }else{
                try{
                    if(compile(options, host)){
                        resolve(true);
                    }else{
                        reject(false);
                    }
                }catch(e){
                    util.writeAbort(e.message);
                    if(e.stack){
                        util.writeAbort(e.stack);
                    }
                    reject(false);
                }
            }
        });
    }
開發者ID:diegovilar,項目名稱:grunt-typescript,代碼行數:26,代碼來源:task.ts

示例5: function

    downloadTool: function (url: string, fileName?: string): Promise<string> {
        return Promise<string>((resolve, reject) => {
            if (process.env["__case__"] == "downloaderror") {
                reject("downloaderror");
            }

            resolve("downloadPath");
        });
    },
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:9,代碼來源:versionInstallerDownloadAndInstallTests.ts

示例6: hashJson

export function hashJson(data: any, algorithm: string): Q.Promise<Buffer> {
  return Q.Promise<Buffer>((resolve, reject) => {
    try {
      resolve(hashJsonSync(data, algorithm));
    } catch (error) {
      reject(error);
    }
  });
}
開發者ID:relution-io,項目名稱:relution-sdk,代碼行數:9,代碼來源:cipher.ts

示例7: testErrors

 // Test that the proper error code and text is passed through on a server error
 function testErrors(method: any): Q.Promise<void> {
     return Q.Promise<void>((resolve: any, reject: any, notify: any) => {
         method().done(() => {
             assert.fail("Should have thrown an error");
             reject();
         }, (error: any) => {
                 assert.equal(error.message, "Text");
                 resolve();
             });
     });
 }
開發者ID:Mrmagana1,項目名稱:code-push,代碼行數:12,代碼來源:management-sdk.ts

示例8: runWithoutDebugOnce

 protected runWithoutDebugOnce(promise: Q.Promise<any>) {
     return Q.Promise<string>((resolve, reject) => {
         let _d = this._debug;
         this._debug = false;
         promise.then(
             (val) => {
                 this._debug = _d;
                 resolve(val);
             },
             (err) => { 
                 this._debug = _d;
                 reject(err);
             }
         );
     });
 }
開發者ID:mattklein999,項目名稱:docker-cmd-js,代碼行數:16,代碼來源:debuggable.ts

示例9: start

  start() {
    return q.Promise((resolve, reject) => {
      this.checkSupportedConfig();

      let args = [
        '--fork',
        '--seleniumAddress',
        this.config.seleniumAddress,
      ];
      if (this.config.webDriverLogDir) {
        args.push('--logDir', this.config.webDriverLogDir);
      }
      if (this.config.highlightDelay) {
        args.push('--highlightDelay', this.config.highlightDelay.toString());
      }
      this.bpProcess = fork(BP_PATH, args, {silent: true});
      logger.info('Starting BlockingProxy with args: ' + args.toString());
      this.bpProcess
          .on('message',
              (data) => {
                this.port = data['port'];
                resolve(data['port']);
              })
          .on('error',
              (err) => {
                reject(new Error('Unable to start BlockingProxy ' + err));
              })
          .on('exit', (code: number, signal: number) => {
            reject(new Error('BP exited with ' + code));
            logger.error('Exited with ' + code);
            logger.error('signal ' + signal);
          });

      this.bpProcess.stdout.on('data', (msg: Buffer) => {
        logger.debug(msg.toString().trim());
      });

      this.bpProcess.stderr.on('data', (msg: Buffer) => {
        logger.error(msg.toString().trim());
      });

      process.on('exit', () => {
        this.bpProcess.kill();
      });
    });
  }
開發者ID:DylanLacey,項目名稱:protractor,代碼行數:46,代碼來源:bpRunner.ts


注:本文中的Q.Promise函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。