vibe.d beta banner
get vibe.d
0.10.1

Asynchronous I/O that doesn’t get in your way, written in D

Function TCPConnection.waitForDataAsync

Waits asynchronously for new data to arrive.

WaitForDataAsyncStatus waitForDataAsync(CALLABLE) (
  CALLABLE read_ready_callback,
  Duration timeout = Duration.max
)
if (is(typeof(() @safe { read_ready_callback(true); } ())));

This function can be used to detach the TCPConnection from a running task while waiting for data, so that the associated memory resources are available for other operations.

Note that read_ready_callback may be called from outside of a task, so no blocking operations may be performed. Instead, an existing task should be notified, or a new one started with runTask.

Parameters

NameDescription
read_ready_callback A callback taking a bool parameter that signals the read-readiness of the connection
timeout Optional timeout to limit the maximum wait time

Returns

If the read readiness can be determined immediately, it will be returned as WaitForDataAsyncStatus.dataAvailable or WaitForDataAsyncStatus.noModeData and the callback will not be invoked. Otherwise WaitForDataAsyncStatus.waiting is returned and the callback will be invoked once the status can be determined or the specified timeout is reached.

Authors

Sönke Ludwig

Copyright

© 2012-2016 Sönke Ludwig

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.