@remix_labs/machine-starter 2.2833.0-dev → 2.2838.0-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/common.js CHANGED
@@ -4,15 +4,19 @@ import { MixcoreTauri, filterFFINames } from "./mixcore.lib.mjs";
4
4
 
5
5
  let workers = {};
6
6
  let children = {};
7
- let ffiSubscriptions = {};
7
+ let ffiLoops = {};
8
8
 
9
9
  function terminateAll() {
10
10
  console.log("[groovebox-starter] terminate all VMs");
11
11
  for (let [vmID, worker] of Object.entries(workers)) {
12
12
  worker.terminate();
13
13
  };
14
+ for (let ffiLoop of Object.values(ffiLoops)) {
15
+ ffiLoop.terminate();
16
+ }
14
17
  workers = {};
15
18
  children = {};
19
+ ffiLoops = {};
16
20
  }
17
21
 
18
22
  function terminateVM(vmID) {
@@ -20,12 +24,12 @@ function terminateVM(vmID) {
20
24
  let worker = workers[vmID];
21
25
  if (worker) {
22
26
  let vmChildren = children[vmID];
23
- let ffiSubscription = ffiSubscriptions[vmID];
27
+ let ffiLoop = ffiLoops[vmID];
24
28
  delete workers[vmID];
25
29
  delete children[vmID];
26
- delete ffiSubscriptions[vmID];
30
+ delete ffiLoops[vmID];
27
31
  worker.terminate();
28
- ffiSubscription.terminate();
32
+ ffiLoop.terminate();
29
33
  if (vmChildren) {
30
34
  for (let subID of vmChildren) {
31
35
  terminateVM(subID)
@@ -68,7 +72,8 @@ async function StartWASM2(hub, config) {
68
72
  let channel = await hub.newChannel();
69
73
  // injected by either index.js or node.js
70
74
  let worker = globalThis.GetMachineWASMWorker();
71
- if (workers[config.vmID]) throw new Error("Cannot start VM, the ID is used: " + config.vmID);
75
+ if (workers[config.vmID] || ffiLoops[config.vmID])
76
+ throw new Error("Cannot start VM, the ID is used: " + config.vmID);
72
77
  workers[config.vmID] = worker;
73
78
  let localFFIs = config.localFFIs || {};
74
79
  let mixcoreFFIs = await getMixcoreFFIs(config.mixcore);
@@ -93,6 +98,7 @@ async function StartWASM2(hub, config) {
93
98
  localFFIfuns["$vm_start"] = ffi_vm_start;
94
99
  localFFIkind["$vm_stop"] = vm_kind;
95
100
  localFFIfuns["$vm_stop"] = ffi_vm_stop;
101
+ ffiLoops[config.vmID] = setupLocalFFIs(hub, config, localFFIfuns);
96
102
  let config_msg =
97
103
  { "_rmx_type": "msg_vm_configure",
98
104
  "baseURL": config.baseURL,
@@ -115,7 +121,6 @@ async function StartWASM2(hub, config) {
115
121
  // (http, https, data)
116
122
  };
117
123
  worker.postMessage(config_msg, [ channel.port ]);
118
- setupLocalFFIs(hub, config, localFFIfuns);
119
124
  return worker;
120
125
  }
121
126
 
@@ -261,13 +266,13 @@ function decode(val) {
261
266
  }
262
267
  }
263
268
 
264
- // set the ffiSubscription and spawn the messaging loop
269
+ // spawn the messaging loop and return an object with a function to terminate
270
+ // the loop `{terminate: () => void}`
265
271
  function setupLocalFFIs(hub, config, localFFIs) {
266
272
  let vmID = config.vmID;
267
273
  let terminate = Promise.withResolvers();
268
- if (ffiSubscriptions[vmID]) ffiSubscriptions[vmID].terminate();
269
- ffiSubscriptions[vmID] = {terminate: terminate.resolve};
270
274
  localFFIsMessageLoop(hub, config, localFFIs, terminate.promise); // don't wait
275
+ return {terminate: terminate.resolve};
271
276
  }
272
277
 
273
278
  async function localFFIsMessageLoop(hub, config, localFFIs, terminate) {
@@ -1,2 +1,2 @@
1
- var GROOVEBOX_BUILD = "3114";
1
+ var GROOVEBOX_BUILD = "3118";
2
2
  export { GROOVEBOX_BUILD }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix_labs/machine-starter",
3
- "version": "2.2833.0-dev",
3
+ "version": "2.2838.0-dev",
4
4
  "description": "start the groove",
5
5
  "main": "node.js",
6
6
  "browser": "index.js",
@@ -11,7 +11,7 @@
11
11
  "author": "Remixlabs staff",
12
12
  "license": "ISC",
13
13
  "dependencies": {
14
- "@remix_labs/hub-client": "2.2833.0-dev",
14
+ "@remix_labs/hub-client": "2.2838.0-dev",
15
15
  "nanoid": "^5.0.2",
16
16
  "web-worker": "^1.2.0"
17
17
  },