• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript once.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中once.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了default函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: connect

    public connect(...args: any[]): any {

        const endpointUrl = args[0];
        const callback = args[1];
        assert(_.isFunction(callback), "expecting a callback");

        this.endpointUrl = endpointUrl;

        debugLog("ClientBaseImpl#connect ", endpointUrl);

        // prevent illegal call to connect
        if (this._secureChannel !== null) {
            setImmediate(() => {
                callback(new Error("connect already called"));
            });
            return;
        }

        if (!this.serverCertificate && this.securityMode !== MessageSecurityMode.None) {

            return this.fetchServerCertificate(endpointUrl, (err?: Error) => {
                if (err) {
                    return callback(err);
                }
                this.connect(endpointUrl, callback);
            });
        }

        // todo: make sure endpointUrl exists in the list of endpoints send by the server
        // [...]

        // make sure callback will only be call once regardless of outcome, and will be also deferred.
        const callbackOnceDelayed: any = once((err?: Error) => setImmediate(() => callback(err)));

        OPCUAClientBase.registry.register(this);

        this._internal_create_secure_channel(this.connectionStrategy, (err: Error | null /* secureChannel?: ClientSecureChannelLayer*/) => {
            // xx secureChannel;
            if (!err) {
                this.emit("connected");
            } else {
                debugLog(chalk.red("SecureChannel creation has failed with error :", err.message));
                if (err.message.match(/ECONNREF/)) {
                    debugLog(chalk.yellow("- The client cannot to :" + endpointUrl + ". Server is not reachable."));
                    err = new Error("The connection cannot be established with server " + endpointUrl + " .\n" +
                      "Please check that the server is up and running or your network configuration.\n" +
                      "Err = (" + err.message + ")");

                } else {
                    debugLog(chalk.yellow("  - The client certificate may not be trusted by the server"));
                    err = new Error("The connection has been rejected by server,\n" +
                      "Please check that client certificate is trusted by server.\n" +
                      "Err = (" + err.message + ")");
                }
                this.emit("connection_failed", err);
            }
            callbackOnceDelayed(err!);
        });

    }
开发者ID:node-opcua,项目名称:node-opcua,代码行数:60,代码来源:client_base_impl.ts


示例2: cb

var init = function (connString: string, cb: any) {
  cb = once(cb);
  var config = parse(connString);
  var srv;

  if (config.servers.length === 1) {
    var opts = config.server_options;
    opts.host = config.servers[0].host || 'localhost';
    opts.port = config.servers[0].port || 27017;
    opts.reconnect = true;
    opts.reconnectInterval = 50;
    srv = new Server(opts);
  } else {
    var rsopts = config.rs_options;
    rsopts.setName = rsopts.rs_name;
    rsopts.reconnect = true;
    rsopts.reconnectInterval = 50;
    srv = new ReplSet(config.servers, rsopts);
  }

  if (config.auth) {
    srv.addAuthProvider('mongocr', new MongoCR());
    srv.on('connect', function (server: any) {
      server.auth('mongocr', config.dbName, config.auth.user, config.auth.password, function (err: any, r: any) {
        if (err) {
          return cb(err);
        }
        cb(null, r);
      });
    });
  } else {
    srv.on('connect', function (server: any) {
      cb(null, server);
    });
  }

  srv.on('error', function (err: any) {
    cb(err);
  });

  srv.connect();
};
开发者ID:prabhu,项目名称:mongots,代码行数:42,代码来源:get-topology.ts


示例3: aggregate

  aggregate(): IAggregationCursor {
    var cb: CallbackType;
    var pipeline = Array.prototype.slice.call(arguments);
    if (typeof pipeline[pipeline.length - 1] === 'function') {
      cb = once(pipeline.pop());
    }

    if (cb) {
      this.runCommand('aggregate', { pipeline: pipeline }, function (err, res) {
        if (err) return cb(err);
        cb(null, res.result);
      });
      return;
    }
    var strm = new AggregationCursor({
      onserver: this._getServer,
      colName: this.name,
      fullCollectionName: this.fullColName(),
      pipeline: pipeline
    });

    return strm;
  }
开发者ID:prabhu,项目名称:mongots,代码行数:23,代码来源:collection.ts


示例4: once



import once from "once";

once(() => 3);
once(() => 3)();
let s = once(() => ({foo: 1}))();
s.foo;

once.proto();

once(() => 3).called && true;
once(() => ({foo: 1})).value.foo;
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:11,代码来源:once-tests.ts



注:本文中的once.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript onoff.Gpio类代码示例发布时间:2022-05-25
下一篇:
TypeScript on-finished.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap