Skip to main content

server.flush(timeout)

Suspends code execution until any pending data has been sent to the server

Availability

Device

Parameters

Name Type Description
timeout Float The maximum time in seconds to wait for pending data to be sent

Returns

Bool — true if the data has been sent, or false on any other outcome

Description

This method waits for any pending data to be sent to the server. If all the data is sent and acknowledged within the timeout period, server.flush() returns true. Otherwise — if any data is still pending after the timeout period has expired, or if an error occurs while sending — it returns false.

Should server.flush() return false, you should not take that as a sign that the data has not been or will not be delivered. The method can return false if, for example, the timeout period is very small. In this case, the flush operation will time out, server.flush() will return false, yet the data could be ACK’d immediately afterwards.

However, the method has no side effects: should it return false, it will not close the connection, for example.

Example Code

This example performs a server.log() shortly before we disconnect from the server. In order to ensure all of the information was sent (and received), we do a server.flush() before disconnecting.