Skip to content

Commit

Permalink
Allow external library to define additional socket handler (#6820)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed May 13, 2024
1 parent ea2d925 commit b24d35e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions panel/io/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def WRITE_LOCK():
_panel_last_cleanup = None
_write_tasks = []

extra_socket_handlers = {}

@dataclasses.dataclass
class Request:
headers : dict
Expand Down Expand Up @@ -177,6 +179,8 @@ async def _dispatch_msgs(doc, msgs):
continue
if isinstance(conn._socket, WebSocketHandler):
futures = dispatch_tornado(conn, msg=msg)
elif (socket_type:= type(conn._socket)) in extra_socket_handlers:
futures = extra_socket_handlers[socket_type](conn, msg=msg)
else:
futures = dispatch_django(conn, msg=msg)
await _run_write_futures(futures)
Expand Down Expand Up @@ -405,6 +409,8 @@ def unlocked() -> Iterator:
continue
elif isinstance(conn._socket, WebSocketHandler):
futures += dispatch_tornado(conn, dispatch_events)
elif (socket_type:= type(conn._socket)) in extra_socket_handlers:
futures += extra_socket_handlers[socket_type](conn, dispatch_events)
else:
futures += dispatch_django(conn, dispatch_events)

Expand Down

0 comments on commit b24d35e

Please sign in to comment.