( pending: PendingRequest[] )
| 146 | // a question names its request and is numbered, as the thread drops an answer |
| 147 | // it stopped waiting for |
| 148 | const 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 | |
| 180 | export const createAsyncPrecompiler = ( |
| 181 | data: Omit< |
no test coverage detected