MQTT API Reference
MQTT 3.1.1 client library
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 );
}
IOT_MQTT_STATUS_PENDING
MQTT operation queued, awaiting result.
Definition: iot_mqtt_types.h:129
IotMqttError_t
IotMqttError_t
Return codes of MQTT functions.
Definition: iot_mqtt_types.h:103
IotMqtt_PublishAsync
IotMqttError_t IotMqtt_PublishAsync(IotMqttConnection_t mqttConnection, const IotMqttPublishInfo_t *pPublishInfo, uint32_t flags, const IotMqttCallbackInfo_t *pCallbackInfo, IotMqttOperation_t *const pPublishOperation)
Publishes a message to the given topic name and optionally receive an asynchronous notification when ...
Definition: iot_mqtt_api.c:1619
IotMqttOperation_t
struct _mqttOperation * IotMqttOperation_t
Opaque handle that references an in-progress MQTT operation.
Definition: iot_mqtt_types.h:88
IotMqtt_Wait
IotMqttError_t IotMqtt_Wait(IotMqttOperation_t operation, uint32_t timeoutMs)
Waits for an operation to complete.
Definition: iot_mqtt_api.c:1916
IOT_MQTT_FLAG_WAITABLE
#define IOT_MQTT_FLAG_WAITABLE
Allows the use of IotMqtt_Wait for blocking until completion.
Definition: iot_mqtt_types.h:1152
IOT_MQTT_OPERATION_INITIALIZER
#define IOT_MQTT_OPERATION_INITIALIZER
Initializer for IotMqttOperation_t.
Definition: iot_mqtt_types.h:1134