本文整理匯總了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;