本文整理匯總了TypeScript中domain-context.get函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript get函數的具體用法?TypeScript get怎麽用?TypeScript get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了get函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setTimeout
export function addTask<T>(task: PromiseLike<T>): PromiseLike<T> {
if (task && domain.active) {
const state = domainContext.get(domainTasksStateKey) as DomainTasksState;
if (state) {
state.numRemainingTasks++;
task.then(() => {
// The application may have other listeners chained to this promise *after*
// this listener, which may in turn register further tasks. Since we don't
// want the combined task to complete until all the handlers for child tasks
// have finished, delay the response to give time for more tasks to be added
// synchronously.
setTimeout(() => {
state.numRemainingTasks--;
if (state.numRemainingTasks === 0 && !state.hasIssuedSuccessCallback) {
state.hasIssuedSuccessCallback = true;
setTimeout(() => {
state.completionCallback(/* error */ null);
}, 0);
}
}, 0);
}, (error) => {
state.completionCallback(error);
});
}
}
return task;
}
示例2: baseUrl
export function baseUrl(url?: string): string {
if (url) {
if (domain.active) {
// There's an active domain (e.g., in Node.js), so associate the base URL with it
domainContext.set(domainTaskStateKey, url);
} else {
// There's no active domain (e.g., in browser), so there's just one shared base URL
noDomainBaseUrl = url;
}
}
return domain.active ? domainContext.get(domainTaskStateKey) : noDomainBaseUrl;
}
示例3: addTask
export function addTask(task: PromiseLike<any>) {
if (task && domain.active) {
const state = domainContext.get(domainTasksStateKey) as DomainTasksState;
if (state) {
state.numRemainingTasks++;
task.then(() => {
// The application may have other listeners chained to this promise *after*
// this listener. Since we don't want the combined task to complete until
// all the handlers for child tasks have finished, delay the following by
// one tick.
setTimeout(() => {
state.numRemainingTasks--;
if (state.numRemainingTasks === 0 && !state.hasIssuedSuccessCallback) {
state.hasIssuedSuccessCallback = true;
state.completionCallback(/* error */ null);
}
}, 0);
}, (error) => {
state.completionCallback(error);
});
}
}
}