waitForResponse = async (requestId) => {
  const { response, error } = await waitForMessage(requestId)

  // In case of an error, fail the lambda invocation with the error
  if (error) {
    console.error(
      'Error occurred during lambda invocation on the local machine:',
    )
    const errorInstance = new Error(error.message) // The error message as streamed from the local machine
    errorInstance.stack = error.stack // The error stack as streamed from the local machine
    errorInstance.name = error.name // The error name as streamed from the local machine

    throw errorInstance
  }

  // In case of a successful response, resolve the lambda invocation with the response
  return response
}
Listens for a message from a device and resolves with the response or an error within a specified timeout period.

This function sets up two promises: one that listens for a single 'message' event from the device, and another that acts as a timeout.
The first promise attempts to parse the incoming message as JSON, distinguishing between successful responses and errors based on
the parsed content. If an error is detected, it constructs an Error instance with details from the received message and rejects the promise.
If a successful response is received, it resolves with the response data. The second promise serves as a fallback, resolving with a
predefined message after a 30-second wait, indicating a timeout occurred. `Promise.race` is used to ensure that the function resolves or
rejects based on whichever promise settles first, effectively implementing a timeout mechanism for the operation.

@returns {Promise<string|Object>} A promise that either resolves with the successful response from the device or a timeout message,
or rejects with an Error instance if the device reports an error. The promise resolves with a string message if the operation times out.