当前位置: 首页>>代码示例>>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;未经允许,请勿转载。