* Send a callback request to the server via the worker. * @param payload The callback payload * @returns Promise that resolves with the callback response
(payload: unknown)
| 206 | * @returns Promise that resolves with the callback response |
| 207 | */ |
| 208 | public async sendCallback(payload: unknown): Promise<CallbackResponse> { |
| 209 | // Wait for initial connection if one is in progress |
| 210 | if (this.connectionPromise && !this.isConnected) { |
| 211 | await this.connectionPromise; |
| 212 | } |
| 213 | |
| 214 | if (!this.worker) { |
| 215 | throw new Error('Worker not connected'); |
| 216 | } |
| 217 | |
| 218 | const requestId = `${this.rendererId}-${++this.requestCounter}`; |
| 219 | |
| 220 | return new Promise((resolve, reject) => { |
| 221 | this.pendingCallbacks.set(requestId, {resolve, reject}); |
| 222 | |
| 223 | this.worker!.port.postMessage({ |
| 224 | type: WorkerMessageType.CALLBACK_REQUEST, |
| 225 | rendererId: this.rendererId, |
| 226 | requestId, |
| 227 | payload |
| 228 | }); |
| 229 | }); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Send a get_props response back to the server. |
no test coverage detected