當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript domain-context.get函數代碼示例

本文整理匯總了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;
}
開發者ID:aspnet,項目名稱:Home,代碼行數:28,代碼來源:main.ts

示例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;
}
開發者ID:An0564,項目名稱:JavaScriptServices,代碼行數:13,代碼來源:fetch.ts

示例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);
            });
        }
    }
}
開發者ID:jimitndiaye,項目名稱:NodeServices,代碼行數:23,代碼來源:main.ts


注:本文中的domain-context.get函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。