MCPcopy
hub / github.com/tornadoweb/tornado / read_message

Method read_message

tornado/websocket.py:1553–1571  ·  view source on GitHub ↗

Reads a message from the WebSocket server. If on_message_callback was specified at WebSocket initialization, this function will never return messages Returns a future whose result is the message, or None if the connection is closed. If a callback argument i

(
        self,
        callback: Optional[Callable[["Future[Union[None, str, bytes]]"], None]] = None,
    )

Source from the content-addressed store, hash-verified

1551 return self.protocol.write_message(message, binary=binary)
1552
1553 def read_message(
1554 self,
1555 callback: Optional[Callable[["Future[Union[None, str, bytes]]"], None]] = None,
1556 ) -> Awaitable[Union[None, str, bytes]]:
1557 """Reads a message from the WebSocket server.
1558
1559 If on_message_callback was specified at WebSocket
1560 initialization, this function will never return messages
1561
1562 Returns a future whose result is the message, or None
1563 if the connection is closed. If a callback argument
1564 is given it will be called with the future when it is
1565 ready.
1566 """
1567
1568 awaitable = self.read_queue.get()
1569 if callback is not None:
1570 self.io_loop.add_future(asyncio.ensure_future(awaitable), callback)
1571 return awaitable
1572
1573 def on_message(self, message: Union[str, bytes]) -> Optional[Awaitable[None]]:
1574 return self._on_message(message)

Callers 15

test_websocket_genMethod · 0.80
test_binary_messageMethod · 0.80
test_unicode_messageMethod · 0.80
test_render_messageMethod · 0.80
test_async_prepareMethod · 0.80
test_path_argsMethod · 0.80
test_coroutineMethod · 0.80

Calls 2

add_futureMethod · 0.80
getMethod · 0.45

Tested by 15

test_websocket_genMethod · 0.64
test_binary_messageMethod · 0.64
test_unicode_messageMethod · 0.64
test_render_messageMethod · 0.64
test_async_prepareMethod · 0.64
test_path_argsMethod · 0.64
test_coroutineMethod · 0.64