| 347 | """ |
| 348 | |
| 349 | def on_done(f: concurrent.futures.Future) -> None: |
| 350 | try: |
| 351 | if shutdown_event.is_set(): |
| 352 | return |
| 353 | result = f.result() |
| 354 | outbound_queue.sync_q.put_nowait( |
| 355 | cast( |
| 356 | str, |
| 357 | to_json( |
| 358 | { |
| 359 | "type": "callback_response", |
| 360 | "rendererId": renderer_id, |
| 361 | "requestId": request_id, |
| 362 | "payload": result, |
| 363 | } |
| 364 | ), |
| 365 | ) |
| 366 | ) |
| 367 | except Exception as e: # pylint: disable=broad-exception-caught |
| 368 | if shutdown_event.is_set(): |
| 369 | return |
| 370 | outbound_queue.sync_q.put_nowait( |
| 371 | cast( |
| 372 | str, |
| 373 | to_json( |
| 374 | { |
| 375 | "type": "callback_response", |
| 376 | "rendererId": renderer_id, |
| 377 | "requestId": request_id, |
| 378 | "payload": { |
| 379 | "status": "error", |
| 380 | "message": str(e), |
| 381 | }, |
| 382 | } |
| 383 | ), |
| 384 | ) |
| 385 | ) |
| 386 | finally: |
| 387 | pending_callbacks.pop(request_id, None) |
| 388 | if not shutdown_event.is_set(): |
| 389 | outbound_queue.sync_q.put_nowait(FLUSH_SIGNAL) |
| 390 | |
| 391 | return on_done |
| 392 | |