MCPcopy
hub / github.com/reflex-dev/reflex / emit_update

Method emit_update

reflex/app.py:1676–1702  ·  view source on GitHub ↗

Emit an update to the client. Args: update: The state update to send. token: The client token (tab) associated with the event.

(self, update: StateUpdate, token: str)

Source from the content-addressed store, hash-verified

1674 return None
1675
1676 async def emit_update(self, update: StateUpdate, token: str) -> None:
1677 """Emit an update to the client.
1678
1679 Args:
1680 update: The state update to send.
1681 token: The client token (tab) associated with the event.
1682 """
1683 socket_record = self._token_manager.token_to_socket.get(token)
1684 if (
1685 socket_record is None
1686 or socket_record.instance_id != self._token_manager.instance_id
1687 ):
1688 if isinstance(self._token_manager, RedisTokenManager):
1689 # The socket belongs to another instance of the app, send it to the lost and found.
1690 await self._token_manager.emit_lost_and_found(token, update)
1691 else:
1692 # If the socket record is None, we are not connected to a client. Prevent sending
1693 # updates to all clients.
1694 console.warn(
1695 f"Attempting to send delta to disconnected client {token!r}"
1696 )
1697 return
1698 # Creating a task prevents the update from being blocked behind other coroutines.
1699 await asyncio.create_task(
1700 self.emit(str(constants.SocketEvent.EVENT), update, to=socket_record.sid),
1701 name=f"reflex_emit_event|{token}|{socket_record.sid}|{time.time()}",
1702 )
1703
1704 async def on_event(self, sid: str, data: Any):
1705 """Event for receiving front-end websocket events.

Callers 5

emit_deltaMethod · 0.80
emit_eventMethod · 0.80
modify_stateMethod · 0.80

Calls 2

emit_lost_and_foundMethod · 0.80
getMethod · 0.45