@livestore/utils 0.4.0-dev.6 → 0.4.0-dev.8

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.
@@ -15,6 +15,15 @@ import * as Scope from 'effect/Scope'
15
15
 
16
16
  // Parent death monitoring setup
17
17
  let parentDeathDetectionEnabled = false
18
+ let parentDeathTimer: NodeJS.Timeout | null = null
19
+
20
+ const stopParentDeathMonitoring = () => {
21
+ parentDeathDetectionEnabled = false
22
+ if (parentDeathTimer) {
23
+ clearTimeout(parentDeathTimer)
24
+ parentDeathTimer = null
25
+ }
26
+ }
18
27
 
19
28
  const setupParentDeathMonitoring = (parentPid: number) => {
20
29
  if (parentDeathDetectionEnabled) return
@@ -25,12 +34,13 @@ const setupParentDeathMonitoring = (parentPid: number) => {
25
34
 
26
35
  // Check if parent is still alive every 2 seconds (more conservative)
27
36
  const checkParentAlive = () => {
37
+ if (!parentDeathDetectionEnabled) return
28
38
  try {
29
39
  // Send signal 0 to check if process exists (doesn't actually send signal)
30
40
  process.kill(parentPid, 0)
31
41
  // If we reach here, parent is still alive, reset failure counter and check again later
32
42
  consecutiveFailures = 0
33
- setTimeout(checkParentAlive, 2000)
43
+ parentDeathTimer = setTimeout(checkParentAlive, 2000)
34
44
  } catch {
35
45
  consecutiveFailures++
36
46
  console.warn(`[Worker ${process.pid}] Parent check failed (${consecutiveFailures}/${maxFailures})`)
@@ -41,13 +51,13 @@ const setupParentDeathMonitoring = (parentPid: number) => {
41
51
  process.exit(0)
42
52
  } else {
43
53
  // Try again sooner on failure
44
- setTimeout(checkParentAlive, 1000)
54
+ parentDeathTimer = setTimeout(checkParentAlive, 1000)
45
55
  }
46
56
  }
47
57
  }
48
58
 
49
59
  // Start monitoring after a longer initial delay to let things settle
50
- setTimeout(checkParentAlive, 5000)
60
+ parentDeathTimer = setTimeout(checkParentAlive, 5000)
51
61
  }
52
62
 
53
63
  const platformRunnerImpl = Runner.PlatformRunner.of({
@@ -101,6 +111,8 @@ const platformRunnerImpl = Runner.PlatformRunner.of({
101
111
  FiberSet.unsafeAdd(fiberSet, fiber)
102
112
  }
103
113
  } else {
114
+ // Graceful shutdown requested by parent: stop monitoring and close port
115
+ stopParentDeathMonitoring()
104
116
  Deferred.unsafeDone(closeLatch, Exit.void)
105
117
  port.close()
106
118
  }
@@ -1,3 +0,0 @@
1
- import { Schema } from 'effect';
2
- export declare const MsgPack: <A, I>(schema: Schema.Schema<A, I>) => Schema.transform<typeof Schema.Uint8ArrayFromSelf, Schema.Schema<A, I, never>>;
3
- //# sourceMappingURL=msgpack.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msgpack.d.ts","sourceRoot":"","sources":["../../../src/effect/Schema/msgpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG/B,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,mFAIrD,CAAA"}
@@ -1,7 +0,0 @@
1
- import { Schema } from 'effect';
2
- import * as msgpack from 'msgpackr';
3
- export const MsgPack = (schema) => Schema.transform(Schema.Uint8ArrayFromSelf, schema, {
4
- encode: (decoded) => msgpack.pack(decoded),
5
- decode: (encodedBytes) => msgpack.unpack(encodedBytes),
6
- });
7
- //# sourceMappingURL=msgpack.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msgpack.js","sourceRoot":"","sources":["../../../src/effect/Schema/msgpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,KAAK,OAAO,MAAM,UAAU,CAAA;AAEnC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAO,MAA2B,EAAE,EAAE,CAC3D,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,EAAE,MAAM,EAAE;IAClD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IAC1C,MAAM,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;CACvD,CAAC,CAAA"}