Skip to content

Commit 20ee44d

Browse files
pfrazeeandrewosh
authored andcommitted
Switch daemon to manual start rather than automatic
1 parent 205dbc1 commit 20ee44d

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ Requires nodejs 14+
2222
npm install -g @hyperspace/cli
2323
```
2424

25+
To start using the network, run:
26+
27+
```
28+
hyp daemon start
29+
```
30+
31+
This will run in the background, sync data for you, until you run:
32+
33+
```
34+
hyp daemon stop
35+
```
36+
2537
## Usage
2638

2739
Command overview:

bin/hyp.js

+9
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ function wrapCommand (obj) {
105105
if (!obj.name.startsWith('daemon') && obj.name !== 'beam') {
106106
await hyper.setup()
107107
}
108+
} catch (err) {
109+
console.error('The daemon is not active. Please run:')
110+
console.error('')
111+
console.error(' hyp daemon start')
112+
console.error('')
113+
process.exit(1)
114+
}
115+
116+
try {
108117
await innerCommand(...args)
109118
} catch (err) {
110119
console.error('Error:', err.message)

lib/commands/daemon/start.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
full: FULL_USAGE
1616
},
1717
command: async function (args) {
18-
await setup()
18+
await setup({canStartDaemon: true})
1919
try {
2020
const client = new HyperspaceClient()
2121
await client.ready()

lib/hyper/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,30 @@ const RETRY_DELAY = 100
1212
var clients = new Map()
1313
var running = new Set()
1414

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)
1818
}
1919

20-
async function setupClient (name, readable, clientFunc) {
20+
async function setupClient (name, readable, clientFunc, canStartDaemon = false) {
2121
let retries = 0
2222
while (!clients.get(name) && retries++ < NUM_RETRIES) {
2323
try {
2424
const client = clientFunc()
2525
await client.ready()
2626
clients.set(name, client)
2727
} catch {
28+
if (!canStartDaemon) break
2829
if (!running.has(name)) {
2930
await startDaemon(name, readable)
3031
running.add(name)
3132
}
3233
await wait(RETRY_DELAY * retries)
3334
}
3435
}
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+
}
3639

3740
const cleanup = async () => {
3841
const client = clients.get(name)

0 commit comments

Comments
 (0)