( responseFile: string, requestId: string, success: boolean, data?: any, error?: string, callback?: () => void )
| 67 | let processing = false; |
| 68 | |
| 69 | function finishProcessing( |
| 70 | responseFile: string, |
| 71 | requestId: string, |
| 72 | success: boolean, |
| 73 | data?: any, |
| 74 | error?: string, |
| 75 | callback?: () => void |
| 76 | ) { |
| 77 | try { |
| 78 | const responseFileLen = view[RESPONSE_FILENAME_LENGTH_INDEX]; |
| 79 | if (responseFileLen > 0 && responseFileLen <= FILENAME_MAX_LENGTH) { |
| 80 | const responseFilePath = join(tmpDir, responseFile); |
| 81 | |
| 82 | const finalResponse = { |
| 83 | requestId, |
| 84 | success, |
| 85 | data: success ? data : undefined, |
| 86 | error: error, |
| 87 | }; |
| 88 | |
| 89 | const encryptedResponse = encrypt(JSON.stringify(finalResponse), aesKey); |
| 90 | writeFileSync(responseFilePath, encryptedResponse); |
| 91 | |
| 92 | Atomics.or(view, 0, 0b010); |
| 93 | Atomics.notify(view, 0); |
| 94 | |
| 95 | if (callback) { |
| 96 | callback(); |
| 97 | } |
| 98 | } |
| 99 | } catch (err) { |
| 100 | log('error', `[Worker] Failed to write response file: ${err}`); |
| 101 | } finally { |
| 102 | processing = false; |
| 103 | Atomics.and(view, 0, ~0b001); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | async function processRequestAsync(): Promise<void> { |
| 108 | let requestFile = ''; |
no test coverage detected