@yolo-croket-dev/core 1.7.44-slowquery.0 → 1.7.44-slowquery.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,6 +8,7 @@ interface RequestContext {
|
|
|
8
8
|
export declare class AbortContext {
|
|
9
9
|
private static asyncLocalStorage;
|
|
10
10
|
private static contextCounter;
|
|
11
|
+
private static pendingAbortCallbacks;
|
|
11
12
|
static run<T>(abortSignal: AbortSignal, requestId: string, callback: (context: RequestContext) => T): T;
|
|
12
13
|
static getCurrentAbortSignal(): AbortSignal | null;
|
|
13
14
|
static getCurrentRequestId(): string | null;
|
|
@@ -15,7 +16,16 @@ export declare class AbortContext {
|
|
|
15
16
|
abortSignal: AbortSignal;
|
|
16
17
|
requestId: string;
|
|
17
18
|
} | null;
|
|
19
|
+
/**
|
|
20
|
+
* 컨텍스트 종료 전에 모든 abort 이벤트 리스너가 완료될 때까지 대기
|
|
21
|
+
*/
|
|
22
|
+
static waitForAbortHandlers(requestId: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* 이 컨텍스트의 모든 abort 이벤트 처리 완료 후 disable 호출
|
|
25
|
+
*/
|
|
26
|
+
static disableAfterAbortHandlers(requestId: string): Promise<void>;
|
|
18
27
|
static disable(): void;
|
|
28
|
+
static disableDeferred(): void;
|
|
19
29
|
static endContext(context?: RequestContext): void;
|
|
20
30
|
static updateContext(updatedData: Partial<RequestContext>): void;
|
|
21
31
|
/**
|
|
@@ -12,6 +12,35 @@ class AbortContext {
|
|
|
12
12
|
createdAt: Date.now(),
|
|
13
13
|
parentContext: currentContext || undefined,
|
|
14
14
|
};
|
|
15
|
+
// abort 이벤트가 발생할 때까지 대기하는 Promise 생성
|
|
16
|
+
const abortPromise = new Promise((resolve) => {
|
|
17
|
+
const checkAbortStatus = () => {
|
|
18
|
+
if (abortSignal.aborted) {
|
|
19
|
+
// 이벤트 루프를 두 번 통과시켜서 모든 abort 리스너가 완료되도록 보장
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
resolve();
|
|
23
|
+
}, 0);
|
|
24
|
+
}, 0);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// 아직 abort가 발생하지 않았으면 즉시 resolve
|
|
28
|
+
resolve();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
abortSignal.addEventListener('abort', checkAbortStatus, { once: true });
|
|
32
|
+
// abort 이벤트가 이미 발생했는지 확인
|
|
33
|
+
if (abortSignal.aborted) {
|
|
34
|
+
checkAbortStatus();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// abort가 발생하지 않은 상태라면 즉시 resolve
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
resolve();
|
|
40
|
+
}, 0);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
this.pendingAbortCallbacks.set(newContext.requestId, abortPromise);
|
|
15
44
|
return this.asyncLocalStorage.run(newContext, callback.bind(this, newContext));
|
|
16
45
|
}
|
|
17
46
|
static getCurrentAbortSignal() {
|
|
@@ -32,9 +61,31 @@ class AbortContext {
|
|
|
32
61
|
}
|
|
33
62
|
return null;
|
|
34
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* 컨텍스트 종료 전에 모든 abort 이벤트 리스너가 완료될 때까지 대기
|
|
66
|
+
*/
|
|
67
|
+
static async waitForAbortHandlers(requestId) {
|
|
68
|
+
const promise = this.pendingAbortCallbacks.get(requestId);
|
|
69
|
+
if (promise) {
|
|
70
|
+
await promise;
|
|
71
|
+
this.pendingAbortCallbacks.delete(requestId);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 이 컨텍스트의 모든 abort 이벤트 처리 완료 후 disable 호출
|
|
76
|
+
*/
|
|
77
|
+
static async disableAfterAbortHandlers(requestId) {
|
|
78
|
+
await this.waitForAbortHandlers(requestId);
|
|
79
|
+
this.asyncLocalStorage.disable();
|
|
80
|
+
}
|
|
35
81
|
static disable() {
|
|
36
82
|
this.asyncLocalStorage.disable();
|
|
37
83
|
}
|
|
84
|
+
static disableDeferred() {
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
this.asyncLocalStorage.disable();
|
|
87
|
+
}, 0);
|
|
88
|
+
}
|
|
38
89
|
// 컨텍스트 종료
|
|
39
90
|
// eslint-disable-next-line consistent-return
|
|
40
91
|
static endContext(context) {
|
|
@@ -89,3 +140,5 @@ class AbortContext {
|
|
|
89
140
|
exports.AbortContext = AbortContext;
|
|
90
141
|
AbortContext.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
91
142
|
AbortContext.contextCounter = 0;
|
|
143
|
+
// abort 이벤트 처리를 추적하기 위한 Map
|
|
144
|
+
AbortContext.pendingAbortCallbacks = new Map();
|
|
@@ -355,8 +355,10 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
355
355
|
}
|
|
356
356
|
},
|
|
357
357
|
error: localErrorProcessor,
|
|
358
|
-
}), (0, operators_1.finalize)(() => {
|
|
358
|
+
}), (0, operators_1.finalize)(async () => {
|
|
359
359
|
this.gracefulShutdownService.popActiveInterceptors(execInterceptor);
|
|
360
|
+
// abort 이벤트 리스너가 모두 완료될 때까지 기다림
|
|
361
|
+
await functions_1.AbortContext.waitForAbortHandlers(execInterceptor.traceId);
|
|
360
362
|
functions_1.AbortContext.disable();
|
|
361
363
|
abortController = null;
|
|
362
364
|
return rxjs_1.EMPTY;
|