MCPcopy
hub / github.com/plotly/dash / make_callback_done_handler

Function make_callback_done_handler

dash/backends/ws.py:326–391  ·  view source on GitHub ↗

Create a done callback handler for executor futures. This factory creates a callback that sends the result back through the WebSocket when an executor future completes. Args: outbound_queue: janus.Queue for sending responses pending_callbacks: Dict tracking pending call

(
    outbound_queue: janus.Queue[str],
    pending_callbacks: Dict[str, concurrent.futures.Future],
    request_id: str,
    renderer_id: str,
    shutdown_event: threading.Event,
)

Source from the content-addressed store, hash-verified

324
325
326def make_callback_done_handler(
327 outbound_queue: janus.Queue[str],
328 pending_callbacks: Dict[str, concurrent.futures.Future],
329 request_id: str,
330 renderer_id: str,
331 shutdown_event: threading.Event,
332) -> Callable[[concurrent.futures.Future], None]:
333 """Create a done callback handler for executor futures.
334
335 This factory creates a callback that sends the result back through
336 the WebSocket when an executor future completes.
337
338 Args:
339 outbound_queue: janus.Queue for sending responses
340 pending_callbacks: Dict tracking pending callbacks for cleanup
341 request_id: The request ID for the callback response
342 renderer_id: The renderer ID for routing the response
343 shutdown_event: Event signaling the websocket connection has closed.
344
345 Returns:
346 A callback function suitable for Future.add_done_callback()
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 ),

Callers 2

websocket_handlerMethod · 0.85
websocket_handlerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…