AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
IotMqtt_Wait

Waits for an operation to complete.

uint32_t timeoutMs );

This function blocks to wait for a subscribe, unsubscribe, or publish to complete. These operations are by default asynchronous; the function calls queue an operation for processing, and a callback is invoked once the operation is complete.

To use this function, the flag IOT_MQTT_FLAG_WAITABLE must have been set in the operation's function call. Additionally, this function must always be called with any waitable operation to clean up resources.

Regardless of its return value, this function always clean up resources used by the waitable operation. This means reference is invalidated as soon as this function returns, even if it returns IOT_MQTT_TIMEOUT or another error.

Parameters
[in]operationReference to the operation to wait for. The flag IOT_MQTT_FLAG_WAITABLE must have been set for this operation.
[in]timeoutMsHow many milliseconds to wait before returning IOT_MQTT_TIMEOUT.
Returns
The return value of this function depends on the MQTT operation associated with reference. See IotMqttError_t for possible return values.

Example

// Operation reference and timeout.
uint32_t timeoutMs = 5000; // 5 seconds
// MQTT operation to wait for.
IotMqttError_t result = IotMqtt_PublishAsync( mqttConnection,
&publishInfo,
NULL,
&publishOperation );
// Publish should have returned IOT_MQTT_STATUS_PENDING. The call to wait
// returns once the result of the publish is available or the timeout expires.
if( result == IOT_MQTT_STATUS_PENDING )
{
result = IotMqtt_Wait( publishOperation, timeoutMs );
// After the call to wait, the result of the publish is known
// (not IOT_MQTT_STATUS_PENDING).
assert( result != IOT_MQTT_STATUS_PENDING );
}