code: function subscribeWhenReady(doctype, socket) {
    if (socket.readyState === WEBSOCKET_STATE.OPEN) {
      try {
        socket.send(
          JSON.stringify({
            method: 'SUBSCRIBE',
            payload: {
              type: doctype
            }
          })
        )
      } catch (error) {
        // eslint-disable-next-line no-console
        console.warn(`Cannot subscribe to doctype ${doctype}: ${error.message}`)
        throw error
      }
    } else {
      setTimeout(() => {
        subscribeWhenReady(doctype, socket)
      }, 10)
    }
  }
docs: Send a subscribe message for the given doctype trough the given websocket, but only if it is in a ready state. If not, retry a few milliseconds later.