@@ -56,48 +56,30 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
5656 */
5757
5858 const fetchHealthData = useCallback ( async servers => {
59- // ipcRenderer.removeAllListeners('healthResponse');
6059
6160 let temp : HealthDataObject [ ] = [ ] ;
62- await Promise . all ( servers . map ( async ( service : string ) => {
63- ipcRenderer . removeAllListeners ( 'healthResponse' ) ;
61+ servers . map ( async ( service : string ) => {
6462
65- try {
66- const newPromise : any = await new Promise ( ( resolve , reject ) => {
67- ipcRenderer . send ( 'healthRequest' , `${ service } ` ) ;
68- ipcRenderer . on ( 'healthResponse' , ( event : Electron . Event , data : string ) => {
69- //V14: the line does not appear necessary, leaving it here commented out in case another group runs into a problem
70- // if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
71- const response = JSON . parse ( data ) ;
72- // console.log({response})
73- const [ dbName ] = Object . keys ( response [ 0 ] )
74- //result exists, has a length prop, and the service name and database name are same
75- console . log ( { service, dbName} )
76- //V14: this block is needed here because of unecessary calls for each service
77- //a prior group was getting the dbName from the response object and since objects dont remember
78- //insertion order they are running all the calls for each service in the array
79- if ( response && response . length && `${ service } ` === dbName ) {
80- resolve ( response [ 0 ] ) ;
81- }
82- // }
83- } ) ;
84- } )
85- temp . push ( newPromise ) ;
86- if ( checkServicesComplete ( temp , [ `${ service } ` ] ) ) {
87- console . log ( { temp} )
63+ try {
8864
65+ ipcRenderer . removeAllListeners ( 'healthResponse' ) ;
66+ ipcRenderer . send ( 'healthRequest' , `${ service } ` ) ;
67+ ipcRenderer . on ( 'healthResponse' , ( event : Electron . Event , data : string ) => {
68+
69+ const response = JSON . parse ( data ) ;
70+ temp . push ( response [ 0 ] ) ;
71+
72+ if ( temp . length === servers . length ) {
73+ console . log ( temp . length , servers . length )
8974 setServices ( [ `${ service } ` ] ) ;
9075 let transformedData : any = { } ;
9176 transformedData = healthTransformer ( temp ) ; //must match the setHealthData STATE format
9277 setHealthData ( transformedData ) ;
9378 }
94- } catch ( err ) {
95- console . log ( "healthcontext.tsx ERROR: " , err ) ;
96- } ;
97- }
98-
99- ) )
100- } , [ ] ) ;
79+ } ) ;
80+ } catch ( err ) {
81+ console . log ( "healthcontext.tsx ERROR: " , err ) ;
82+ } } ) } , [ ] ) ;
10183
10284 const checkServicesComplete = ( temp : any [ ] , servers : string [ ] ) => {
10385 if ( temp . length !== servers . length ) {
0 commit comments