@@ -72,27 +72,33 @@ export default class {
72
72
return this . check ( 'all' )
73
73
}
74
74
75
- async check ( keys ) {
76
- if ( keys === "all" ) {
77
- await this . check ( this . checks )
78
- return this . results . raw ( )
79
- }
80
-
81
- if ( typeof keys === 'string' )
82
- return this . _check ( keys )
75
+ async rawResult ( key , raw ) {
83
76
84
- if ( keys instanceof Array && keys . length ) {
85
- let result = { }
77
+ }
78
+
79
+ async check ( keys , raw = true ) {
80
+ let result
81
+ if ( keys == "all" ) {
82
+ console . log ( 'check all' )
83
+ return this . check ( this . checks )
84
+ }
85
+ else if ( typeof keys === 'string' ) {
86
+ result = await this . _check ( keys )
87
+ }
88
+ else if ( keys instanceof Array && keys . length ) {
86
89
for ( const key of keys ) {
87
- result = { ... result , ... await this . _check ( key ) }
90
+ await this . _check ( key )
88
91
}
89
- return new Promise ( resolve => resolve ( result ) )
92
+ result = this . results . raw ( keys )
93
+ }
94
+ else {
95
+ return this . throw ( `check(${ keys } ) failed. keys must be string or populated array` )
90
96
}
91
- return this . throw ( `check( ${ keys } ) failed. keys must be string or populated array` )
97
+ return raw ? result : this . results . cleanResult ( keys , result )
92
98
}
93
99
94
100
async _check ( key ) {
95
- this . logger . debug ( `check( ${ key } )` )
101
+ this . logger . debug ( `${ key } : check( )` )
96
102
this . defaultAdapters ( )
97
103
await this . start ( key )
98
104
const result = await this . promises . get ( key ) . promise
@@ -121,16 +127,16 @@ export default class {
121
127
this . adapters [ adapter ] [ `check_${ key } ` ] ( )
122
128
} )
123
129
. catch ( ( precheck ) => {
124
- if ( precheck . error === true ) {
125
- this . logger . debug ( `${ key } : precheck rejected with error` )
126
- this . logger . error ( `Error in ${ key } precheck: ${ precheck . error } ` )
127
- this . promises . get ( key ) . resolve ( { [ key ] : false , [ `${ key } Latency` ] : - 1 , ...precheck } )
128
- }
129
- else if ( key === 'connect' && precheck . error === false && precheck ?. result ) {
130
+ if ( key === 'connect' && precheck . status == "error" && precheck ?. result ) {
130
131
this . logger . debug ( `${ key } : precheck rejected with cached result` )
131
132
this . logger . warn ( `Precheck found that connect check was already fulfilled, returning cached result` )
132
133
this . promises . get ( key ) . resolve ( precheck . result )
133
134
}
135
+ else if ( precheck . status == "error" ) {
136
+ this . logger . debug ( `${ key } : precheck rejected with error` )
137
+ this . logger . err ( `Error in ${ key } precheck: ${ precheck . error } ` )
138
+ this . promises . get ( key ) . resolve ( { [ key ] : false , [ `${ key } Latency` ] : - 1 , ...precheck } )
139
+ }
134
140
else {
135
141
throw new Error ( `start(): precheck rejection for ${ key } should not ever get here: ${ JSON . stringify ( precheck ) } ` )
136
142
}
@@ -149,9 +155,10 @@ export default class {
149
155
const adapter_name = this . adapters [ adapter_key ] . constructor . name
150
156
const adapters = [ ...new Set ( this . results . get ( 'adapters' ) . concat ( [ adapter_name ] ) ) ]
151
157
const checked_at = Date . now ( )
152
- data . duration = this . latency . duration ( key )
153
- this . results . setMany ( { checked_at, adapters, [ key ] : { ...data } } )
154
- this . promises . get ( key ) . resolve ( { url, network, checked_at, adapters, ...data } )
158
+ data . duration = this . latency . duration ( key )
159
+ const result = { url, network, checked_at, adapters, [ key ] : { ...data } }
160
+ this . results . setMany ( result )
161
+ this . promises . get ( key ) . resolve ( result )
155
162
this . on_change ( )
156
163
}
157
164
@@ -214,21 +221,7 @@ export default class {
214
221
//Websocket is not connecting, key is not connect
215
222
if ( ! keyIsConnect && ! this . isConnected ( ) ) {
216
223
this . logger . debug ( `${ key } : prechecker(): websocket is not connecting, key is not connect` )
217
- const error = { status : "error" , message : `Cannot check ${ key } , no active websocket connection to relay` }
218
- if ( connectAttempted ) {
219
- this . logger . debug ( `${ key } : prechecker(): websocket is not connecting, key is not connect, connectAttempted is true` )
220
- this . logger . warn ( `Error in ${ key } precheck: ${ error . message } ` )
221
- return rejectPrecheck ( error )
222
- }
223
- const result = await this . check ( 'connect' )
224
- if ( result . connect ) {
225
- this . logger . debug ( `${ key } : prechecker(): websocket is not connecting, key is not connect, connectAttempted is false, connect check succeeded` )
226
- return resolvePrecheck ( )
227
- }
228
- else {
229
- this . logger . debug ( `${ key } : prechecker(): websocket is not connecting, key is not connect, connectAttempted is false, connect check failed` )
230
- return rejectPrecheck ( error )
231
- }
224
+ return rejectPrecheck ( { status : "error" , message : `Cannot check ${ key } , no active websocket connection to relay` } )
232
225
}
233
226
this . logger . debug ( `${ key } : Made it here without resolving or rejecting precheck. You missed something.` )
234
227
}
0 commit comments