本文整理汇总了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;未经允许,请勿转载。 |
请发表评论