本文整理汇总了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!);
});
}
示例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();
};
示例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;
}
示例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;