@@ -12,27 +12,30 @@ const RETRY_DELAY = 100
12
12
var clients = new Map ( )
13
13
var running = new Set ( )
14
14
15
- export async function setup ( ) {
16
- await setupClient ( 'hyperspace' , 'Hyperspace' , ( ) => new HyperspaceClient ( ) )
17
- await setupClient ( 'hyperspace-mirroring-service' , 'Mirroring' , ( ) => new MirroringClient ( ) )
15
+ export async function setup ( { canStartDaemon } = { canStartDaemon : false } ) {
16
+ await setupClient ( 'hyperspace' , 'Hyperspace' , ( ) => new HyperspaceClient ( ) , canStartDaemon )
17
+ await setupClient ( 'hyperspace-mirroring-service' , 'Mirroring' , ( ) => new MirroringClient ( ) , canStartDaemon )
18
18
}
19
19
20
- async function setupClient ( name , readable , clientFunc ) {
20
+ async function setupClient ( name , readable , clientFunc , canStartDaemon = false ) {
21
21
let retries = 0
22
22
while ( ! clients . get ( name ) && retries ++ < NUM_RETRIES ) {
23
23
try {
24
24
const client = clientFunc ( )
25
25
await client . ready ( )
26
26
clients . set ( name , client )
27
27
} catch {
28
+ if ( ! canStartDaemon ) break
28
29
if ( ! running . has ( name ) ) {
29
30
await startDaemon ( name , readable )
30
31
running . add ( name )
31
32
}
32
33
await wait ( RETRY_DELAY * retries )
33
34
}
34
35
}
35
- if ( ! clients . has ( name ) ) throw new Error ( `Could not connect to the ${ readable } daemon.` )
36
+ if ( ! clients . has ( name ) ) {
37
+ throw new Error ( `Could not connect to the ${ readable } daemon.` )
38
+ }
36
39
37
40
const cleanup = async ( ) => {
38
41
const client = clients . get ( name )
0 commit comments