You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/server/README.md
+72-6Lines changed: 72 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,78 @@ Server capable of running multiple concurrent simulations that can be controlled
4
4
5
5
https://github.com/thefrontside/simulacrum
6
6
7
-
> [!WARNING]
8
-
> The server is undergoing a refactor, and this may not be required for your use case. The refactor includes allow for more simply running single simulators so this package will be primarily useful as a control plane for cases where there are many simulators under test and in use. For the previous iterations, see the `v0` branch which contain the previous functionality.
7
+
## Getting Started
8
+
9
+
Set up a process or simulators such as this example `service-graph.ts`.
10
+
11
+
```ts service-graph.ts
12
+
#!/usr/bin/envnode
13
+
import { run } from"effection";
14
+
import {
15
+
useServiceGraph,
16
+
simulationCLI,
17
+
useChildSimulation,
18
+
useSimulation,
19
+
useService,
20
+
} from"@simulacrum/server";
21
+
import { simulation } from"./sim2.ts";
22
+
23
+
// define your "graph" that can be used through a CLI or as part of a test rig
// this is a helper function which will give you a CLI around this service graph
43
+
// if you are calling this file directly
44
+
import { fileURLToPath } from"node:url";
45
+
if (process.argv[1] ===fileURLToPath(import.meta.url)) {
46
+
simulationCLI(services);
47
+
}
48
+
```
49
+
50
+
From this, you have two main entry points. One may start it directly from your shell.
51
+
52
+
```bash
53
+
# start a local service graph defined in ./service-graph.ts
54
+
node --import tsx ./simulators/service-graph.ts
55
+
```
56
+
57
+
> [!NOTE]
58
+
> We use `--import tsx` here to automatically handle the typescript conversion. This is a separate package that you may be interested in using, but it not a hard requirement necessarily.
59
+
60
+
Secondly, we can use this in tests. It is convenient to place in an `beforeAll()` or a `beforeEach()`. This is built on `effection`, and should handle all shutdown and clean up of the services when the function passes out of lexical scope.
Previously services could expose their return value via a public `exportsOperation` that consumers could await. That mechanism has been removed in this branch as we move to a child-process-focused runner model. Provider-returned values are still delivered to dependent service factories internally, but no longer exposed as an operation on the public `services` map.
143
213
144
214
For convenience tests may use the `servicePorts` map exposed by the running graph to discover HTTP ports that services registered when they start. The `servicePorts` map is available on the object returned by the runner and contains service name => port when a service's `operation` returns an object with a `{ port: number }` property.
0 commit comments