code: async def write_close_frame(self, data: bytes = b"") -> None:
          
          # Test and set the connection state before sending the close frame to
          # avoid sending two frames in case of concurrent calls.
          if self.state is State.OPEN:
              # 7.1.3. The WebSocket Closing Handshake is Started
              self.state = State.CLOSING
              logger.debug("%s - state = CLOSING", self.side)
  
              # 7.1.2. Start the WebSocket Closing Handshake
              await self.write_frame(True, OP_CLOSE, data, _expected_state=State.CLOSING)
docs: Write a close frame if and only if the connection state is OPEN.
  
          This dedicated coroutine must be used for writing close frames to
          ensure that at most one close frame is sent on a given connection.