@@ -14,6 +14,7 @@ import { Seer } from "./Seer";
14
14
import { Swarm } from "./Swarm" ;
15
15
import { TNS } from "./TNS" ;
16
16
import { X509 } from "./X509" ;
17
+ import { Health } from "./Health" ;
17
18
18
19
class ExtendedAuth extends Auth {
19
20
private wrappers : {
@@ -73,6 +74,7 @@ export class Taucorder {
73
74
seer ?: Seer ;
74
75
swarm ?: Swarm ;
75
76
tns ?: TNS ;
77
+ health ?: Health ;
76
78
} = { } ;
77
79
78
80
constructor ( rpcUrl : string , config : Config ) {
@@ -151,4 +153,42 @@ export class Taucorder {
151
153
}
152
154
return this . wrappers . tns ;
153
155
}
156
+
157
+ Health ( ) {
158
+ if ( ! this . wrappers . health ) {
159
+ this . wrappers . health = new Health ( this . transport ) ;
160
+ }
161
+ return this . wrappers . health ;
162
+ }
163
+ }
164
+
165
+ export class TaucorderService extends Health {
166
+ constructor ( rpcUrl : string ) {
167
+ const transport = createConnectTransport ( {
168
+ baseUrl : rpcUrl ,
169
+ httpVersion : "1.1" ,
170
+ } ) ;
171
+ super ( transport ) ;
172
+ }
173
+
174
+ /**
175
+ * Wait for the service to become available by pinging until success or timeout
176
+ * @param timeoutSeconds Maximum time to wait in seconds
177
+ * @throws Error if service does not become available within timeout
178
+ */
179
+ async wait ( timeoutSeconds : number ) : Promise < void > {
180
+ const start = Date . now ( ) ;
181
+ const timeoutMs = timeoutSeconds * 1000 ;
182
+
183
+ while ( Date . now ( ) - start < timeoutMs ) {
184
+ try {
185
+ await this . ping ( ) ;
186
+ return ;
187
+ } catch ( err ) {
188
+ // Wait 100ms before retrying
189
+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
190
+ }
191
+ }
192
+ throw new Error ( `Service did not become available within ${ timeoutSeconds } seconds` ) ;
193
+ }
154
194
}
0 commit comments