MCPcopy Create free account
hub / github.com/arktypeio/arktype / resolvingChannelOf

Function resolvingChannelOf

ark/aot/worker.ts:148–178  ·  view source on GitHub ↗
(
	pending: PendingRequest[]
)

Source from the content-addressed store, hash-verified

146// a question names its request and is numbered, as the thread drops an answer
147// it stopped waiting for
148const resolvingChannelOf = (
149 pending: PendingRequest[]
150):
151 | { resolver: MessagePort; resolved: Int32Array; close: () => void }
152 | undefined => {
153 if ("bun" in process.versions) return
154 const { port1, port2 } = new MessageChannel()
155 const resolved = new Int32Array(new SharedArrayBuffer(4))
156 port1.on(
157 "message",
158 async ([question, index, specifier, importer]: [
159 number,
160 number,
161 string,
162 string
163 ]) => {
164 const resolve = pending.find(entry => entry.index === index)?.resolve
165 // null where the request can't ask, so the driver can ask again
166 const path =
167 resolve ?
168 await resolve(specifier, importer).catch(() => undefined)
169 : null
170 port1.postMessage([question, path])
171 // counts the answers, so one arriving as the thread waits wakes it
172 Atomics.add(resolved, 0, 1)
173 Atomics.notify(resolved, 0)
174 }
175 )
176 port1.unref()
177 return { resolver: port2, resolved, close: () => port1.close() }
178}
179
180export const createAsyncPrecompiler = (
181 data: Omit<

Callers 1

createAsyncPrecompilerFunction · 0.85

Calls 4

findMethod · 0.80
resolveFunction · 0.70
closeMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected