本文整理汇总了TypeScript中continuation-local-storage.createNamespace函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createNamespace函数的具体用法?TypeScript createNamespace怎么用?TypeScript createNamespace使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createNamespace函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
t.test("handler added but no listeners registered", function (t) {
t.plan(3);
var http = require('http')
, n = cls.createNamespace('no_listener')
;
// only fails on Node < 0.10
var server = http.createServer(function (req: any, res: any) {
n.bindEmitter(req);
t.doesNotThrow(function () {
req.emit('event');
});
res.writeHead(200, {"Content-Length" : 4});
res.end('WORD');
});
server.listen(8080);
http.get('http://localhost:8080/', function (res: any) {
t.equal(res.statusCode, 200, "request came back OK");
res.setEncoding('ascii');
res.on('data', function (body: any) {
t.equal(body, 'WORD');
server.close();
cls.destroyNamespace('no_listener');
});
});
});
示例2: test
test("simple tracer built on contexts", function (t) {
var tracer = cls.createNamespace('tracer');
class Trace {
harvester: any;
constructor(harvester: any) {
this.harvester = harvester;
}
runHandler(callback: any) {
var wrapped = tracer.bind(function () {
callback();
this.harvester.emit('finished', tracer.get('transaction'));
}.bind(this));
wrapped();
}
}
t.plan(6);
var harvester = new EventEmitter();
var trace = new Trace(harvester);
harvester.on('finished', function (transaction: any) {
t.ok(transaction, "transaction should have been passed in");
t.equal(transaction.status, 'ok', "transaction should have finished OK");
// t.equal(Object.keys(process.namespaces).length, 1, "Should only have one namespace.");
});
trace.runHandler(function inScope() {
t.ok(tracer.active, "tracer should have an active context");
tracer.set('transaction', {status : 'ok'});
t.ok(tracer.get('transaction'), "can retrieve newly-set value");
t.equal(tracer.get('transaction').status, 'ok', "value should be correct");
});
});
示例3: constructor
constructor() {
this._basename = path.basename(module.filename);
let dbConfig = configs.getDatabaseConfig();
if (dbConfig.logging) {
dbConfig.logging = logger.info;
}
(SequelizeStatic as any).cls = cls.createNamespace("sequelize-transaction");
this._sequelize = new SequelizeStatic(dbConfig.database, dbConfig.username,
dbConfig.password, dbConfig);
this._models = ({} as any);
fs.readdirSync(__dirname).filter((file: string) => {
return (file !== this._basename) && (file !== "interfaces");
}).forEach((file: string) => {
let model = this._sequelize.import(path.join(__dirname, file));
this._models[(model as any).name] = model;
});
Object.keys(this._models).forEach((modelName: string) => {
if (typeof this._models[modelName].associate === "function") {
this._models[modelName].associate(this._models);
}
});
}
示例4: initilize
export function initilize(publisher: string, name: string, version: string, aiKey: string): void {
if (reporter) {
throw new Error("TelemetryReporter already initilized.");
}
if (aiKey) {
reporter = new TelemetryReporter(`${publisher}.${name}`, version, aiKey);
report(EventType.ACTIVATION);
}
if (!sessionNamespace) {
sessionNamespace = createNamespace("sessionNamespace");
}
}
示例5: require
const token = options.token;
if (!token) {
console.log('トークンが指定されていません' + parser.getUsage());
process.exit(1);
}
const databaseUrl: string = options['database-url'];
if (!databaseUrl) {
console.log('--database-urlが指定されていません' + parser.getUsage());
process.exit(1);
}
// Sequelizeのトランザクションを、全てのクエリで自動的に利用する設定
// http://docs.sequelizejs.com/en/latest/docs/transactions/#automatically-pass-transactions-to-all-queries
const cls = require('continuation-local-storage');
Sequelize.cls = cls.createNamespace('hx');
const botkit = require('botkit');
const controller = botkit.slackbot({
debug: false
});
const bot = controller.spawn({
token,
incoming_webhook: {
url: 'https://hooks.slack.com/services/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'
}
})
.startRTM(function(err: any): void {
if (err) {
示例6: get
export function get(): Toe {
let ns = retrieve(NS) || create(NS);
let toe = option(ns.get(LABEL))
.get_or_else(new Toe(nonce()));
ns.run(() => ns.set(LABEL, toe));
return toe.clone();
}
示例7: initialize
export function initialize(session: string, tick: Function): void {
let ns = retrieve(NS) || create(NS);
let toe = new Toe(part(session, KEY_SESSION))
.for_request(nonce());
ns.run(() => {
ns.set(LABEL, toe);
tick(null, toe.clone());
});
}