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


TypeScript Q.nbind函數代碼示例

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


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

示例1: upnpConf

async function upnpConf (noupnp:boolean, logger:any) {
  const client = require('nat-upnp').createClient();
  // Look for 2 random ports
  const publicPort = await getAvailablePort(client)
  const privatePort = publicPort
  const conf:NetworkConfDTO = {
    proxiesConf: undefined,
    nobma: true,
    bmaWithCrawler: false,
    port: privatePort,
    ipv4: '127.0.0.1',
    ipv6: '::1',
    dos: null,
    upnp: false,
    httplogs: false,
    remoteport: publicPort,
    remotehost: null,
    remoteipv4: null,
    remoteipv6: null
  }
  logger && logger.info('Checking UPnP features...');
  if (noupnp) {
    throw Error('No UPnP');
  }
  const publicIP = await Q.nbind(client.externalIp, client)();
  await Q.nbind(client.portMapping, client)({
    public: publicPort,
    private: privatePort,
    ttl: BMAConstants.UPNP_TTL
  });
  const privateIP = await Q.Promise((resolve:any, reject:any) => {
    client.findGateway((err:any, res:any, localIP:any) => {
      if (err) return reject(err);
      resolve(localIP);
    });
  });
  conf.remoteipv4 = publicIP.match(BMAConstants.IPV4_REGEXP) ? publicIP : null;
  conf.remoteport = publicPort;
  conf.port = privatePort;
  conf.ipv4 = privateIP.match(BMAConstants.IPV4_REGEXP) ? privateIP : null;
  return conf;
}
開發者ID:duniter,項目名稱:duniter,代碼行數:42,代碼來源:network.ts

示例2: getAvailablePort

async function getAvailablePort(client:any) {
  const mappings:{ public: { port:number }}[] = await Q.nbind(client.getMappings, client)();
  const externalPortsUsed = mappings.map(m => m.public.port)
  let availablePort = BMAConstants.BMA_PORTS_START
  while (externalPortsUsed.indexOf(availablePort) !== -1 && availablePort <= BMAConstants.BMA_PORTS_END) {
    availablePort++
  }
  if (availablePort > BMAConstants.BMA_PORTS_END) {
    throw "No port available for UPnP"
  }
  return availablePort
}
開發者ID:Kalmac,項目名稱:duniter,代碼行數:12,代碼來源:network.ts

示例3: findGateway

 async findGateway() {
   try {
     const client = upnp.createClient();
     const res = await Q.nbind(client.findGateway, client)();
     const desc = res && res[0] && res[0].description;
     if (desc) {
       const match = desc.match(/(\d+.\d+.\d+.\d+):/);
       if (match) {
         return match[1];
       }
     }
     return null;
   } catch (e) {
     return null;
   }
 }
開發者ID:duniter,項目名稱:duniter,代碼行數:16,代碼來源:upnp.ts

示例4: function

export const Upnp = async function (localPort:number, remotePort:number, logger:any, conf:ConfDTO) {
  "use strict";

  logger.info('UPnP: configuring...');
  const api = new UpnpApi(localPort, remotePort, logger, conf)
  try {
    await api.openPort()
  } catch (e) {
    const client = upnp.createClient();
    try {
      await Q.nbind(client.externalIp, client)();
    } catch (err) {
      if (err && err.message == 'timeout') {
        throw 'No UPnP gateway found: your node won\'t be reachable from the Internet. Use --noupnp option to avoid this message.'
      }
      throw err;
    } finally {
      client.close();
    }
  }
  return api
};
開發者ID:duniter,項目名稱:duniter,代碼行數:22,代碼來源:upnp.ts

示例5: require

const _ = require('lodash')
const FS  = require('fs')
const Q  = require('q')
const glob = require('glob')
const sass = require('node-sass')

let globSearch = Q.denodeify(glob)
let sassRender = Q.nbind(sass.render, sass)
let writeFile = Q.denodeify(FS.writeFile)
let sassDefaults = {
  includePaths: [
  ],
  indentedSyntax: true
}

globSearch('src/**/*.scss')
  .then((files) => {
    var result = Q()
    files.forEach((srcFile) => {
      result = result
        .then(() => {
          let dstFile = srcFile.replace(/\.scss$/i, '.css')
          return buildSassFile(srcFile, dstFile)
        })
    })
    return result
  })
  .then(() => {
    console.log('Compiled CSS files.')
  })
  .catch((err) => {
開發者ID:ng-cookbook,項目名稱:angular2-redux-complex-ui,代碼行數:31,代碼來源:build-css.ts


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