@@ -52,17 +52,11 @@ export function useFailedTransactionsCorrelations() {
52
52
[ ]
53
53
) ;
54
54
55
- // `abortCtrl` is used to cancel individual requests that already started.
56
- // `isCancelledRef` is used to cancel the overall task in between requests in the `startFetch` callback.
57
55
const abortCtrl = useRef ( new AbortController ( ) ) ;
58
- // We're using a ref here because otherwise the startFetch function might have
59
- // a stale value for checking if the task has been cancelled.
60
- const isCancelledRef = useRef ( false ) ;
61
56
62
57
const startFetch = useCallback ( async ( ) => {
63
58
abortCtrl . current . abort ( ) ;
64
59
abortCtrl . current = new AbortController ( ) ;
65
- isCancelledRef . current = false ;
66
60
67
61
setResponse ( {
68
62
...getInitialResponse ( ) ,
@@ -85,36 +79,46 @@ export function useFailedTransactionsCorrelations() {
85
79
ccsWarning : false ,
86
80
} ;
87
81
88
- // Initial call to fetch the overall distribution for the log-log plot.
89
- const { overallHistogram, percentileThresholdValue } = await callApmApi ( {
90
- endpoint : 'POST /internal/apm/latency/overall_distribution' ,
91
- signal : abortCtrl . current . signal ,
92
- params : {
93
- body : {
94
- ...fetchParams ,
95
- percentileThreshold : DEFAULT_PERCENTILE_THRESHOLD ,
96
- } ,
97
- } ,
98
- } ) ;
99
- responseUpdate . overallHistogram = overallHistogram ;
100
- responseUpdate . percentileThresholdValue = percentileThresholdValue ;
82
+ const [ overallHistogramResponse , errorHistogramRespone ] =
83
+ await Promise . all ( [
84
+ // Initial call to fetch the overall distribution for the log-log plot.
85
+ callApmApi ( {
86
+ endpoint : 'POST /internal/apm/latency/overall_distribution' ,
87
+ signal : abortCtrl . current . signal ,
88
+ params : {
89
+ body : {
90
+ ...fetchParams ,
91
+ percentileThreshold : DEFAULT_PERCENTILE_THRESHOLD ,
92
+ } ,
93
+ } ,
94
+ } ) ,
95
+ callApmApi ( {
96
+ endpoint : 'POST /internal/apm/latency/overall_distribution' ,
97
+ signal : abortCtrl . current . signal ,
98
+ params : {
99
+ body : {
100
+ ...fetchParams ,
101
+ percentileThreshold : DEFAULT_PERCENTILE_THRESHOLD ,
102
+ termFilters : [
103
+ {
104
+ fieldName : EVENT_OUTCOME ,
105
+ fieldValue : EventOutcome . failure ,
106
+ } ,
107
+ ] ,
108
+ } ,
109
+ } ,
110
+ } ) ,
111
+ ] ) ;
112
+
113
+ const { overallHistogram, percentileThresholdValue } =
114
+ overallHistogramResponse ;
115
+ const { overallHistogram : errorHistogram } = errorHistogramRespone ;
101
116
102
- const { overallHistogram : errorHistogram } = await callApmApi ( {
103
- endpoint : 'POST /internal/apm/latency/overall_distribution' ,
104
- signal : abortCtrl . current . signal ,
105
- params : {
106
- body : {
107
- ...fetchParams ,
108
- percentileThreshold : DEFAULT_PERCENTILE_THRESHOLD ,
109
- termFilters : [
110
- { fieldName : EVENT_OUTCOME , fieldValue : EventOutcome . failure } ,
111
- ] ,
112
- } ,
113
- } ,
114
- } ) ;
115
117
responseUpdate . errorHistogram = errorHistogram ;
118
+ responseUpdate . overallHistogram = overallHistogram ;
119
+ responseUpdate . percentileThresholdValue = percentileThresholdValue ;
116
120
117
- if ( isCancelledRef . current ) {
121
+ if ( abortCtrl . current . signal . aborted ) {
118
122
return ;
119
123
}
120
124
@@ -132,7 +136,7 @@ export function useFailedTransactionsCorrelations() {
132
136
} ,
133
137
} ) ;
134
138
135
- if ( isCancelledRef . current ) {
139
+ if ( abortCtrl . current . signal . aborted ) {
136
140
return ;
137
141
}
138
142
@@ -182,7 +186,7 @@ export function useFailedTransactionsCorrelations() {
182
186
PROGRESS_STEP_P_VALUES ,
183
187
} ) ;
184
188
185
- if ( isCancelledRef . current ) {
189
+ if ( abortCtrl . current . signal . aborted ) {
186
190
return ;
187
191
}
188
192
}
@@ -204,7 +208,7 @@ export function useFailedTransactionsCorrelations() {
204
208
setResponse ( { ...responseUpdate , loaded : LOADED_DONE , isRunning : false } ) ;
205
209
setResponse . flush ( ) ;
206
210
} catch ( e ) {
207
- if ( ! isCancelledRef . current ) {
211
+ if ( ! abortCtrl . current . signal . aborted ) {
208
212
const err = e as Error | IHttpFetchError < ResponseErrorBody > ;
209
213
setResponse ( {
210
214
error :
@@ -219,7 +223,6 @@ export function useFailedTransactionsCorrelations() {
219
223
} , [ fetchParams , setResponse ] ) ;
220
224
221
225
const cancelFetch = useCallback ( ( ) => {
222
- isCancelledRef . current = true ;
223
226
abortCtrl . current . abort ( ) ;
224
227
setResponse ( {
225
228
isRunning : false ,
@@ -231,7 +234,6 @@ export function useFailedTransactionsCorrelations() {
231
234
useEffect ( ( ) => {
232
235
startFetch ( ) ;
233
236
return ( ) => {
234
- isCancelledRef . current = true ;
235
237
abortCtrl . current . abort ( ) ;
236
238
} ;
237
239
} , [ startFetch , cancelFetch ] ) ;
0 commit comments