@yaks/process 0.0.0-stage → 0.2.36

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.
Files changed (111) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +249 -2
  3. package/_dist/clock.d.ts +5 -0
  4. package/_dist/clock.d.ts.map +1 -0
  5. package/_dist/command.d.ts +43 -0
  6. package/_dist/command.d.ts.map +1 -0
  7. package/_dist/comp.d.ts +49 -0
  8. package/_dist/comp.d.ts.map +1 -0
  9. package/_dist/env.d.ts +8 -0
  10. package/_dist/env.d.ts.map +1 -0
  11. package/_dist/graph.d.ts +3 -0
  12. package/_dist/graph.d.ts.map +1 -0
  13. package/_dist/http.d.ts +11 -0
  14. package/_dist/http.d.ts.map +1 -0
  15. package/_dist/isolate.d.ts +11 -0
  16. package/_dist/isolate.d.ts.map +1 -0
  17. package/_dist/mod.d.ts +49 -0
  18. package/_dist/mod.d.ts.map +1 -0
  19. package/_dist/modules.d.ts +31 -0
  20. package/_dist/modules.d.ts.map +1 -0
  21. package/_dist/platform.d.ts +7 -0
  22. package/_dist/platform.d.ts.map +1 -0
  23. package/_dist/plugin.d.ts +15 -0
  24. package/_dist/plugin.d.ts.map +1 -0
  25. package/_dist/run.d.ts +219 -0
  26. package/_dist/run.d.ts.map +1 -0
  27. package/_dist/self.d.ts +32 -0
  28. package/_dist/self.d.ts.map +1 -0
  29. package/_dist/socket.d.ts +11 -0
  30. package/_dist/socket.d.ts.map +1 -0
  31. package/_dist/store.d.ts +22 -0
  32. package/_dist/store.d.ts.map +1 -0
  33. package/_dist/system.d.ts +64 -0
  34. package/_dist/system.d.ts.map +1 -0
  35. package/_dist/trash.d.ts +6 -0
  36. package/_dist/trash.d.ts.map +1 -0
  37. package/_dist/views.d.ts +4 -0
  38. package/_dist/views.d.ts.map +1 -0
  39. package/_dist/vocab.d.ts +8 -0
  40. package/_dist/vocab.d.ts.map +1 -0
  41. package/_dist/wind.d.ts +35 -0
  42. package/_dist/wind.d.ts.map +1 -0
  43. package/clock.js +11 -0
  44. package/clock.js.map +1 -0
  45. package/clock.ts +11 -0
  46. package/command.js +172 -0
  47. package/command.js.map +1 -0
  48. package/command.ts +215 -0
  49. package/comp.js +54 -0
  50. package/comp.js.map +1 -0
  51. package/comp.ts +123 -0
  52. package/deno.json +1 -0
  53. package/detached.js +60 -0
  54. package/detached.js.map +1 -0
  55. package/detached.ts +92 -0
  56. package/detached_worker.ts +22 -0
  57. package/env.js +13 -0
  58. package/env.js.map +1 -0
  59. package/env.ts +24 -0
  60. package/graph.js +7 -0
  61. package/graph.js.map +1 -0
  62. package/graph.ts +8 -0
  63. package/http.js +158 -0
  64. package/http.js.map +1 -0
  65. package/http.ts +184 -0
  66. package/isolate.js +41 -0
  67. package/isolate.js.map +1 -0
  68. package/isolate.ts +52 -0
  69. package/mod.js +49 -0
  70. package/mod.js.map +1 -0
  71. package/mod.ts +50 -0
  72. package/modules.js +41 -0
  73. package/modules.js.map +1 -0
  74. package/modules.ts +69 -0
  75. package/package.json +81 -4
  76. package/platform.js +9 -0
  77. package/platform.js.map +1 -0
  78. package/platform.ts +9 -0
  79. package/plugin.js +27 -0
  80. package/plugin.js.map +1 -0
  81. package/plugin.ts +28 -0
  82. package/run.js +899 -0
  83. package/run.js.map +1 -0
  84. package/run.ts +1139 -0
  85. package/self.js +93 -0
  86. package/self.js.map +1 -0
  87. package/self.ts +144 -0
  88. package/socket.js +38 -0
  89. package/socket.js.map +1 -0
  90. package/socket.ts +49 -0
  91. package/store.js +30 -0
  92. package/store.js.map +1 -0
  93. package/store.ts +50 -0
  94. package/system.js +161 -0
  95. package/system.js.map +1 -0
  96. package/system.ts +216 -0
  97. package/testing.ts +39 -0
  98. package/tidy.ts +28 -0
  99. package/trash.js +117 -0
  100. package/trash.js.map +1 -0
  101. package/trash.ts +117 -0
  102. package/views.js +28 -0
  103. package/views.js.map +1 -0
  104. package/views.ts +30 -0
  105. package/vocab.js +16 -0
  106. package/vocab.js.map +1 -0
  107. package/vocab.json +154 -0
  108. package/vocab.ts +18 -0
  109. package/wind.js +88 -0
  110. package/wind.js.map +1 -0
  111. package/wind.ts +114 -0
package/vocab.json ADDED
@@ -0,0 +1,154 @@
1
+ {
2
+ "$id": "urn:uuid:9b2c7d08-a2ab-40f8-802c-1506b1239538",
3
+ "title": "process",
4
+ "$defs": {
5
+ "service": {
6
+ "$id": "urn:uuid:15d7eef3-71dd-411a-ab51-52c2a0f83692",
7
+ "component": true,
8
+ "journal": false,
9
+ "type": "object",
10
+ "description": "a program that should be running. It is stored on the same entity its `process` component lands on: the service records what is wanted, the process records what is actually running, and a `stop` component beside it means the program is no longer wanted",
11
+ "properties": {
12
+ "command": {
13
+ "$id": "urn:uuid:0645da35-6940-4ed1-85bf-dac6e1fe81b5",
14
+ "type": "string",
15
+ "description": "the command line to run, argv joined by spaces \u2014 the supervisor's own copy, kept here rather than read back off the running process, because restarting needs the command that was asked for and not what the kernel reports"
16
+ },
17
+ "cwd": {
18
+ "$id": "urn:uuid:0ad0d6df-5de5-4c87-9ec4-996c28d76f1a",
19
+ "type": "string",
20
+ "description": "the working directory to run it in; absent means the supervisor's own working directory"
21
+ },
22
+ "restart": {
23
+ "$id": "urn:uuid:b51aa570-8cb0-41a3-99af-b0c768a67b15",
24
+ "type": "string",
25
+ "enum": [
26
+ "never",
27
+ "on-failure",
28
+ "always"
29
+ ],
30
+ "description": "what to do when it exits, using systemd's three values; absent means never, so a service that does not set it runs once and stays down"
31
+ },
32
+ "attempts": {
33
+ "$id": "urn:uuid:623bde4c-d2c4-48e0-9d3e-762b120fa969",
34
+ "type": "integer",
35
+ "description": "how many times the supervisor has restarted it after an exit \u2014 the backoff grows with this number, and a run that outlives the longest backoff resets the count"
36
+ }
37
+ }
38
+ },
39
+ "process": {
40
+ "$id": "urn:uuid:b7a4d4f3-e939-4e29-bdc1-cb82318183a5",
41
+ "component": true,
42
+ "journal": false,
43
+ "type": "object",
44
+ "description": "a program observed on its launch workspace; its entity id, not a pid alone, is the durable process handle",
45
+ "properties": {
46
+ "pid": {
47
+ "$id": "urn:uuid:6776369c-8ddb-4145-b87b-cab6c55cee5f",
48
+ "type": "integer",
49
+ "description": "the process id on the machine tracking it \u2014 the only durable handle an adopted process has"
50
+ },
51
+ "command": {
52
+ "$id": "urn:uuid:108add78-7e11-4421-80dc-734404a5b607",
53
+ "type": "string",
54
+ "description": "the command line it was launched with, argv joined by spaces; absent when the process was adopted rather than started here"
55
+ },
56
+ "cwd": {
57
+ "$id": "urn:uuid:40445dc3-8d4c-413a-8ae0-17694f6e794c",
58
+ "type": "string",
59
+ "description": "the working directory it was launched in; absent for the same reason as command"
60
+ },
61
+ "roles": {
62
+ "$id": "urn:uuid:9ce0b806-5655-421a-8987-510d9cad6ae2",
63
+ "type": "array",
64
+ "items": {
65
+ "type": "string"
66
+ },
67
+ "description": "the roles it serves, where it opened a graph: graph, web, effects, or a plugin's service by its name; absent for a program that opened none"
68
+ },
69
+ "handle": {
70
+ "$id": "urn:uuid:332a776d-b11c-428c-9054-54e1f347e44a",
71
+ "type": "string",
72
+ "stamped": true,
73
+ "description": "the workspace backend's process handle, when different from the graph process id"
74
+ },
75
+ "workspace": {
76
+ "$id": "urn:uuid:f446209c-0bb2-4fdb-9778-c4a01e48a47d",
77
+ "type": "string",
78
+ "ref": "workspace",
79
+ "death": "keep",
80
+ "description": "the original launch workspace, retained for wait, stop and output recovery; absent placement is unknown, never local"
81
+ },
82
+ "watcher": {
83
+ "$id": "urn:uuid:300d3fb9-5dd4-49a1-a2ee-1a9891ea4267",
84
+ "type": "string",
85
+ "ref": "entity",
86
+ "death": "detach",
87
+ "description": "the process (an entity) launching it and reading how it goes, or the one that took it up after; a run whose watcher is over is the next process's to take up, and one it never launched is started again"
88
+ }
89
+ }
90
+ },
91
+ "runtime": {
92
+ "$id": "urn:uuid:c27665d8-0a13-4292-8f00-80ba17bc1be3",
93
+ "component": true,
94
+ "journal": false,
95
+ "type": "object",
96
+ "description": "what a process runs on, written by the process about itself when it starts, beside its `process` component: the JavaScript runtime, its version and the operating system. It is how a failure in that process says what it ran on",
97
+ "properties": {
98
+ "name": {
99
+ "$id": "urn:uuid:6798f5b8-1ab9-492e-a9ed-797cc4fcda60",
100
+ "type": "string",
101
+ "description": "the runtime, lowercase: deno"
102
+ },
103
+ "version": {
104
+ "$id": "urn:uuid:69381af7-276b-44e7-8843-0e084bdadc51",
105
+ "type": "string",
106
+ "description": "the runtime's version: 2.5.1"
107
+ },
108
+ "os": {
109
+ "$id": "urn:uuid:baad6797-36b9-4e40-bc1e-b0c2f395f8a8",
110
+ "type": "string",
111
+ "description": "the operating system and its release, as the runtime reports them: linux 6.8.0-45-generic, darwin 24.1.0"
112
+ }
113
+ }
114
+ },
115
+ "exit": {
116
+ "$id": "urn:uuid:300f1cca-b07b-4bf7-9a06-399e4ffc98f9",
117
+ "component": true,
118
+ "journal": false,
119
+ "type": "object",
120
+ "description": "the process has ended \u2014 never rewritten, and deleted only by the transaction that records the next attempt on a supervised entity",
121
+ "properties": {
122
+ "code": {
123
+ "$id": "urn:uuid:c8c3cc99-be3d-484a-ae70-5353252e1d4e",
124
+ "type": "integer",
125
+ "description": "the exit code it reported; absent when the end of the process was observed but the code was not (a signal killed the wrapper, or nothing was watching)"
126
+ },
127
+ "oom": {
128
+ "$id": "urn:uuid:4b64c05b-9f35-44e8-8bcd-34ccdf908cb4",
129
+ "type": "integer",
130
+ "description": "how many of the run's processes the kernel's OOM killer ended at its memory limit while it ran (Linux, its scope's memory.events); absent when none were or nothing counts them"
131
+ },
132
+ "reason": {
133
+ "$id": "urn:uuid:26a89f9a-39de-422c-94ca-2ac17687d57d",
134
+ "type": "string",
135
+ "enum": ["disk_full", "exit_write_failed", "reboot"],
136
+ "description": "a storage failure observed while the process was ending, or the machine restarting under it (reboot), which ends a run with no code"
137
+ }
138
+ }
139
+ }
140
+ },
141
+ "kinds": {
142
+ "service": {
143
+ "$id": "urn:uuid:15d7eef3-71dd-411a-ab51-52c2a0f83692",
144
+ "description": "a program that should be running. It is stored on the same entity its `process` component lands on: the service records what is wanted, the process records what is actually running, and a `stop` component beside it means the program is no longer wanted",
145
+ "before": [
146
+ "process"
147
+ ]
148
+ },
149
+ "process": {
150
+ "$id": "urn:uuid:b7a4d4f3-e939-4e29-bdc1-cb82318183a5",
151
+ "description": "a program observed on its launch workspace; its entity id, not a pid alone, is the durable process handle"
152
+ }
153
+ }
154
+ }
package/vocab.ts ADDED
@@ -0,0 +1,18 @@
1
+ // The process components and nothing else, exported as `@yaks/process/vocab`
2
+ // for a caller that only needs to know the shape of the data. It imports no
3
+ // storage, no SQL and no runtime code, so a browser tab loading this
4
+ // vocabulary loads nothing else.
5
+
6
+ import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
7
+ import { processDoc } from './comp.js'
8
+ import manifest from './package.json' with { type: 'json' }
9
+
10
+ export { processDoc }
11
+ export { EXIT, PROCESS, RUNTIME, SERVICE } from './comp.js'
12
+
13
+ /** What this package is: its manifest's description, the one place it is
14
+ * written, which a host stamps on each document here. */
15
+ export let description: string = manifest.description
16
+
17
+ /** Every vocabulary document this plugin declares. */
18
+ export let docs: VocabDoc[] = [processDoc]
package/wind.js ADDED
@@ -0,0 +1,88 @@
1
+ import { resolvers } from "@yaks/fp";
2
+ import * as system from "./system.js";
3
+ /**
4
+ * A wind of its own, for a test; a process has {@link wind}.
5
+ *
6
+ * ```ts
7
+ * import { assertEquals } from '@std/assert'
8
+ * import { winding } from '@yaks/process/wind'
9
+ *
10
+ * let w = winding()
11
+ * let said: string[] = []
12
+ * w.hold({ drain: () => said.push('drain'), force: () => said.push('force') })
13
+ * w.interrupt(143)
14
+ * assertEquals([await w.done, said], [143, ['drain']])
15
+ * ```
16
+ */ export let winding = ()=>{
17
+ let holds = new Set();
18
+ let state = 'open';
19
+ let end = resolvers();
20
+ // Every hold asked at once; one that throws has still answered.
21
+ let each = (ask)=>Promise.allSettled([
22
+ ...holds
23
+ ].map(async (h)=>await ask(h)));
24
+ return {
25
+ hold: (h)=>{
26
+ holds.add(h);
27
+ return ()=>void holds.delete(h);
28
+ },
29
+ get draining () {
30
+ return state != 'open';
31
+ },
32
+ done: end.promise,
33
+ interrupt: (code)=>{
34
+ if (state == 'open') {
35
+ state = 'draining';
36
+ each((h)=>h.drain()).then(()=>{
37
+ if (state != 'draining') return;
38
+ state = 'done';
39
+ end.resolve(code);
40
+ });
41
+ } else if (state == 'draining') {
42
+ state = 'forced';
43
+ each((h)=>h.force?.()).then(()=>end.resolve(code));
44
+ }
45
+ }
46
+ };
47
+ };
48
+ /** This process's wind. */ export let wind = winding();
49
+ /** The signals a process winds down on, and the code each ends it with: 128
50
+ * plus the signal's number, as a shell reports it. Windows delivers SIGINT
51
+ * alone. */ export let SIGNALS = system.build.os == 'windows' ? [
52
+ [
53
+ 'SIGINT',
54
+ 130
55
+ ]
56
+ ] : [
57
+ [
58
+ 'SIGTERM',
59
+ 143
60
+ ],
61
+ [
62
+ 'SIGINT',
63
+ 130
64
+ ],
65
+ [
66
+ 'SIGHUP',
67
+ 129
68
+ ]
69
+ ];
70
+ // The winds already listening, so a second listener does not make one signal
71
+ // two interrupts.
72
+ let heard = new WeakSet();
73
+ /** Hear {@link SIGNALS} as interrupts of `w`. Whoever listens first listens
74
+ * for the process, and the function returned stops; listening again is a
75
+ * no-op. */ export let listen = (w = wind)=>{
76
+ if (heard.has(w)) return ()=>{};
77
+ heard.add(w);
78
+ let on = SIGNALS.map(([s, code])=>[
79
+ s,
80
+ ()=>w.interrupt(code)
81
+ ]);
82
+ for (let [s, fn] of on)system.addSignalListener(s, fn);
83
+ return ()=>{
84
+ heard.delete(w);
85
+ for (let [s, fn] of on)system.removeSignalListener(s, fn);
86
+ };
87
+ };
88
+ //# sourceMappingURL=wind.js.map
package/wind.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wind.js","sources":["./wind.ts"],"names":[],"mappings":"AAAA,SAAS,SAAS,wBAA6B;AAC/C,YAAY,0BAAyB;AAwCrC;;;;;;;;;;;;;CAaC,GACD,OAAO,IAAI,UAAU;EACnB,IAAI,QAAQ,IAAI;EAChB,IAAI,QAAiD;EACrD,IAAI,MAAM;EACV,gEAAgE;EAChE,IAAI,OAAO,CAAC,MACV,QAAQ,UAAU,CAAC;SAAI;KAAM,CAAC,GAAG,CAAC,OAAO,IAAM,MAAM,IAAI;EAC3D,OAAO;IACL,MAAM,CAAC;MACL,MAAM,GAAG,CAAC;MACV,OAAO,IAAM,KAAK,MAAM,MAAM,CAAC;IACjC;IACA,IAAI,YAAW;MACb,OAAO,SAAS;IAClB;IACA,MAAM,IAAI,OAAO;IACjB,WAAW,CAAC;MACV,IAAI,SAAS,QAAQ;QACnB,QAAQ;QACR,KAAK,CAAC,IAAM,EAAE,KAAK,IAAI,IAAI,CAAC;UAC1B,IAAI,SAAS,YAAY;UACzB,QAAQ;UACR,IAAI,OAAO,CAAC;QACd;MACF,OAAO,IAAI,SAAS,YAAY;QAC9B,QAAQ;QACR,KAAK,CAAC,IAAM,EAAE,KAAK,MAAM,IAAI,CAAC,IAAM,IAAI,OAAO,CAAC;MAClD;IACF;EACF;AACF,EAAC;AAED,yBAAyB,GACzB,OAAO,IAAI,OAAa,UAAS;AAEjC;;UAEU,GACV,OAAO,IAAI,UAAqC,OAAO,KAAK,CAAC,EAAE,IAAI,YAC/D;EAAC;IAAC;IAAU;GAAI;CAAC,GACjB;EAAC;IAAC;IAAW;GAAI;EAAE;IAAC;IAAU;GAAI;EAAE;IAAC;IAAU;GAAI;CAAC,CAAA;AAExD,6EAA6E;AAC7E,kBAAkB;AAClB,IAAI,QAAQ,IAAI;AAEhB;;UAEU,GACV,OAAO,IAAI,SAAS,CAAC,IAAU,IAAI;EACjC,IAAI,MAAM,GAAG,CAAC,IAAI,OAAO,KAAO;EAChC,MAAM,GAAG,CAAC;EACV,IAAI,KAAK,QAAQ,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,GAAK;MAAC;MAAG,IAAM,EAAE,SAAS,CAAC;KAAM;EAChE,KAAK,IAAI,CAAC,GAAG,GAAG,IAAI,GAAI,OAAO,iBAAiB,CAAC,GAAG;EACpD,OAAO;IACL,MAAM,MAAM,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,GAAG,IAAI,GAAI,OAAO,oBAAoB,CAAC,GAAG;EACzD;AACF,EAAC"}
package/wind.ts ADDED
@@ -0,0 +1,114 @@
1
+ import { resolvers } from '@yaks/fp'
2
+ import * as system from './system.js'
3
+ // How this process ends when it is asked to: wound down, not cut off, unless
4
+ // it is asked twice.
5
+ //
6
+ // An interrupt is a signal (SIGTERM from a service manager, SIGINT from
7
+ // ctrl-c, SIGHUP from a terminal going away) or a ctrl-c typed into a raw
8
+ // terminal (@yaks/tui). Whatever keeps the process open holds it
9
+ // ({@link Hold}): the graphs a command opened, a terminal it paints, a backend
10
+ // a view runs. The first interrupt asks every hold to drain: take nothing new
11
+ // and let what it started finish. Nothing here puts a clock on that, because
12
+ // only the work knows how long it needs. The second interrupt forces: what is still going is ended where it
13
+ // stands. Once every hold has answered, the process is done, with the code of
14
+ // the interrupt that ended it.
15
+ //
16
+ // A signal is the whole process's, so there is one wind per process
17
+ // ({@link wind}): a command line, the terminal it draws and the graphs it
18
+ // opened all answer the same interrupt.
19
+
20
+ /** What holds the process open while it winds down. */
21
+ export type Hold = {
22
+ /** take nothing new and finish what was started; settles once finished */
23
+ drain: () => unknown
24
+ /** end what is still going, where it stands */
25
+ force?: () => unknown
26
+ }
27
+
28
+ /** A process winding down: what holds it, and the interrupts it hears. */
29
+ export type Wind = {
30
+ /** hold the process open while it winds down; the function returned lets
31
+ * go */
32
+ hold: (h: Hold) => () => void
33
+ /** an interrupt: the first drains every hold, a second forces them. `code`
34
+ * is what the process ends with, 128 plus a signal's number. */
35
+ interrupt: (code: number) => void
36
+ /** whether an interrupt has come */
37
+ readonly draining: boolean
38
+ /** settles with the code once every hold has drained, or been forced */
39
+ done: Promise<number>
40
+ }
41
+
42
+ /**
43
+ * A wind of its own, for a test; a process has {@link wind}.
44
+ *
45
+ * ```ts
46
+ * import { assertEquals } from '@std/assert'
47
+ * import { winding } from '@yaks/process/wind'
48
+ *
49
+ * let w = winding()
50
+ * let said: string[] = []
51
+ * w.hold({ drain: () => said.push('drain'), force: () => said.push('force') })
52
+ * w.interrupt(143)
53
+ * assertEquals([await w.done, said], [143, ['drain']])
54
+ * ```
55
+ */
56
+ export let winding = (): Wind => {
57
+ let holds = new Set<Hold>()
58
+ let state: 'open' | 'draining' | 'forced' | 'done' = 'open'
59
+ let end = resolvers<number>()
60
+ // Every hold asked at once; one that throws has still answered.
61
+ let each = (ask: (h: Hold) => unknown) =>
62
+ Promise.allSettled([...holds].map(async (h) => await ask(h)))
63
+ return {
64
+ hold: (h) => {
65
+ holds.add(h)
66
+ return () => void holds.delete(h)
67
+ },
68
+ get draining() {
69
+ return state != 'open'
70
+ },
71
+ done: end.promise,
72
+ interrupt: (code) => {
73
+ if (state == 'open') {
74
+ state = 'draining'
75
+ each((h) => h.drain()).then(() => {
76
+ if (state != 'draining') return
77
+ state = 'done'
78
+ end.resolve(code)
79
+ })
80
+ } else if (state == 'draining') {
81
+ state = 'forced'
82
+ each((h) => h.force?.()).then(() => end.resolve(code))
83
+ }
84
+ },
85
+ }
86
+ }
87
+
88
+ /** This process's wind. */
89
+ export let wind: Wind = winding()
90
+
91
+ /** The signals a process winds down on, and the code each ends it with: 128
92
+ * plus the signal's number, as a shell reports it. Windows delivers SIGINT
93
+ * alone. */
94
+ export let SIGNALS: [system.Signal, number][] = system.build.os == 'windows'
95
+ ? [['SIGINT', 130]]
96
+ : [['SIGTERM', 143], ['SIGINT', 130], ['SIGHUP', 129]]
97
+
98
+ // The winds already listening, so a second listener does not make one signal
99
+ // two interrupts.
100
+ let heard = new WeakSet<Wind>()
101
+
102
+ /** Hear {@link SIGNALS} as interrupts of `w`. Whoever listens first listens
103
+ * for the process, and the function returned stops; listening again is a
104
+ * no-op. */
105
+ export let listen = (w: Wind = wind): () => void => {
106
+ if (heard.has(w)) return () => {}
107
+ heard.add(w)
108
+ let on = SIGNALS.map(([s, code]) => [s, () => w.interrupt(code)] as const)
109
+ for (let [s, fn] of on) system.addSignalListener(s, fn)
110
+ return () => {
111
+ heard.delete(w)
112
+ for (let [s, fn] of on) system.removeSignalListener(s, fn)
113
+ }
114
+ }