TWaitSet
The TWaitSet implements a reactor pattern and allows to wait on multiple events in one single call (TWaitSet.WaitAndProcessOnce) until it wakes up or to run repeatedly with (TWaitSet.WaitAndProcess) until an interrupt or termination signal was received or the user has explicitly requested to stop by returning TCallbackProgression.Stop in the provided callback.
The TListener can be attached as well as sockets or anything else that can be packed into a TFileDescriptorView.
Can be created via the TWaitSetBuilder.
Definition
Unit: Neslib.Iceoryx2.WaitSet
Properties
| Name | Description |
|---|---|
| Capacity | Returns the capacity of the TWaitSet |
| Count | Returns the number of attachments. |
| Handle | |
| IsEmpty | Returns True if the TWaitSet has no attachments, otherwise False. |
| SignalHandlingMode | Returns the TSignalHandlingMode with which the TWaitSet was created. |
Constructors
| Name | Description |
|---|---|
| Assign | |
| Finalize | |
| Initialize |
Operators
| Name | Description |
|---|---|
| Equal | |
| NotEqual |
Methods
| Name | Description |
|---|---|
| AttachDeadline(TFileDescriptorBased, TDuration) | Attaches a TFileDescriptorBased object as deadline to the TWaitSet. Whenever the event is received or the deadline is hit, the user is informed in TWaitSet.WaitAndProcess. The object cannot be attached twice and the TWaitSet.Capacity is limited by the underlying implementation. Whenever the object emits an event the deadline is reset by the TWaitSet. |
| AttachDeadline(TListener, TDuration) | Attaches a TListener as deadline to the TWaitSet. Whenever the event is received or the deadline is hit, the user is informed in TWaitSet.WaitAndProcess. The object cannot be attached twice and the TWaitSet.Capacity is limited by the underlying implementation. Whenever the object emits an event the deadline is reset by the TWaitSet. |
| AttachInterval | Attaches a tick event to the TWaitSet. Whenever the timeout is reached the TWaitSet informs the user in TWaitSet.WaitAndProcess. |
| AttachNotification(TFileDescriptorBased) | Attaches a TFileDescriptorBased object as notification to the TWaitSet. Whenever an event is received on the object the TWaitSet informs the user in TWaitSet.WaitAndProcess to handle the event. The object cannot be attached twice and the TWaitSet.Capacity is limited by the underlying implementation. |
| AttachNotification(TListener) | Attaches a TListener as notification to the TWaitSet. Whenever an event is received on the object the TWaitSet informs the user in TWaitSet.WaitAndProcess to handle the event. The object cannot be attached twice and the TWaitSet.Capacity is limited by the underlying implementation. |
| WaitAndProcess | Waits until an event arrives on the TWaitSet, then collects all events by calling the provided callback with the corresponding TWaitSetAttachmentId. In contrast to [TWaitSet.WaitAndProcessOnce it will never return until the user explicitly requests it by returning TCallbackProgression.Stop or by receiving a signal. |
| WaitAndProcessOnce | Waits until an event arrives on the TWaitSet, then collects all events by calling the provided callback with the corresponding TWaitSetAttachmentId and then returns. This makes it ideal to be called in some kind of event-loop. |
| WaitAndProcessOnceWithTimeout | Waits until an event arrives on the TWaitSet or the provided timeout has passed, then collects all events by calling the provided callback with the corresponding TWaitSetAttachmentId and then returns. This makes it ideal to be called in some kind of event-loop. |
Property Descriptions
Capacity
Returns the capacity of the TWaitSet
property Capacity: Int64 read GetCapacity
Type: Int64
Count
Returns the number of attachments.
property Count: Int64 read GetCount
Type: Int64
Handle
property Handle: THandle read GetHandle
Type: THandle
IsEmpty
Returns True if the TWaitSet has no attachments, otherwise False.
property IsEmpty: Boolean read GetIsEmpty
Type: Boolean
SignalHandlingMode
Returns the TSignalHandlingMode with which the TWaitSet was created.
property SignalHandlingMode: TSignalHandlingMode read GetSignalHandlingMode
Type: TSignalHandlingMode
Constructor Descriptions
Assign
constructor Assign(var ADest: TWaitSet; const ASrc: TWaitSet)
Parameters
ADest: TWaitSet
ASrc: TWaitSet
Finalize
destructor Finalize
Initialize
constructor Initialize
Operator Descriptions
Equal(TWaitSet, Pointer)
class operator Equal(const ALeft: TWaitSet; const ARight: Pointer): Boolean; inline; static
Parameters
ALeft: TWaitSet
ARight: Pointer
Returns
Boolean
NotEqual(TWaitSet, Pointer)
class operator NotEqual(const ALeft: TWaitSet; const ARight: Pointer): Boolean; inline; static
Parameters
ALeft: TWaitSet
ARight: Pointer
Returns
Boolean
Method Descriptions
AttachDeadline(TFileDescriptorBased, TDuration)
Attaches a TFileDescriptorBased object as deadline to the TWaitSet. Whenever the event is received or the deadline is hit, the user is informed in TWaitSet.WaitAndProcess. The object cannot be attached twice and the TWaitSet.Capacity is limited by the underlying implementation. Whenever the object emits an event the deadline is reset by the TWaitSet.
function AttachDeadline(const AAttachment: TFileDescriptorBased; const ADeadline: TDuration): TResult<TWaitSetGuard, TWaitSetAttachmentError>; overload
Parameters
AAttachment: TFileDescriptorBased
ADeadline: TDuration
Returns
TResult<TWaitSetGuard, TWaitSetAttachmentError>
Remarks
- The corresponding TFileDescriptor must live at least as long as the returned TWaitSetGuard. You can call TWaitSetGuard.Release to ensure it is released before the attachment. * The TWaitSetGuard must live at least as long as the TWaitsSet.
AttachDeadline(TListener, TDuration)
Attaches a TListener as deadline to the TWaitSet. Whenever the event is received or the deadline is hit, the user is informed in TWaitSet.WaitAndProcess. The object cannot be attached twice and the TWaitSet.Capacity is limited by the underlying implementation. Whenever the object emits an event the deadline is reset by the TWaitSet.
function AttachDeadline(const AListener: TListener; const ADeadline: TDuration): TResult<TWaitSetGuard, TWaitSetAttachmentError>; overload
Parameters
AListener: TListener
ADeadline: TDuration
Returns
TResult<TWaitSetGuard, TWaitSetAttachmentError>
Remarks
- The corresponding TListener must live at least as long as the returned TWaitSetGuard. You can call TWaitSetGuard.Release to ensure it is released before the listener. * The TWaitSetGuard must live at least as long as the TWaitsSet.
AttachInterval(TDuration)
Attaches a tick event to the TWaitSet. Whenever the timeout is reached the TWaitSet informs the user in TWaitSet.WaitAndProcess.
function AttachInterval(const ADeadline: TDuration): TResult<TWaitSetGuard, TWaitSetAttachmentError>
Parameters
ADeadline: TDuration
Returns
TResult<TWaitSetGuard, TWaitSetAttachmentError>
Remarks
The TWaitSetGuard must live at least as long as the TWaitsSet.
AttachNotification(TFileDescriptorBased)
Attaches a TFileDescriptorBased object as notification to the TWaitSet. Whenever an event is received on the object the TWaitSet informs the user in TWaitSet.WaitAndProcess to handle the event. The object cannot be attached twice and the TWaitSet.Capacity is limited by the underlying implementation.
function AttachNotification(const AAttachment: TFileDescriptorBased): TResult<TWaitSetGuard, TWaitSetAttachmentError>; overload
Parameters
AAttachment: TFileDescriptorBased
Returns
TResult<TWaitSetGuard, TWaitSetAttachmentError>
Remarks
- The corresponding TFileDescriptor must live at least as long as the returned TWaitSetGuard. You can call TWaitSetGuard.Release to ensure it is released before the attachment. * The TWaitSetGuard must live at least as long as the TWaitsSet.
AttachNotification(TListener)
Attaches a TListener as notification to the TWaitSet. Whenever an event is received on the object the TWaitSet informs the user in TWaitSet.WaitAndProcess to handle the event. The object cannot be attached twice and the TWaitSet.Capacity is limited by the underlying implementation.
function AttachNotification(const AListener: TListener): TResult<TWaitSetGuard, TWaitSetAttachmentError>; overload
Parameters
AListener: TListener
Returns
TResult<TWaitSetGuard, TWaitSetAttachmentError>
Remarks
- The TListener must live at least as long as the returned TWaitSetGuard. You can call TWaitSetGuard.Release to ensure it is released before the listener. * The TWaitSetGuard must live at least as long as the TWaitSet.
WaitAndProcess(TCallback<TWaitSetAttachmentId>)
Waits until an event arrives on the TWaitSet, then collects all events by calling the provided callback with the corresponding TWaitSetAttachmentId. In contrast to [TWaitSet.WaitAndProcessOnce it will never return until the user explicitly requests it by returning TCallbackProgression.Stop or by receiving a signal.
The provided callback must return TCallbackProgression.Continue to continue the event processing and handle the next event or TCallbackProgression.Stop to return from this call immediately. All unhandled events will be lost forever and the call will return TWaitSetRunResult.StopRequest.
If an interrupt- (SIGINT) or a termination-signal (SIGTERM) was received, it will exit the loop and inform the user with TWaitSetRunResult.Interrupt or TWaitSetRunResult.TerminationRequest.
function WaitAndProcess(const ACallback: TCallback<TWaitSetAttachmentId>): TResult<TWaitSetRunResult, TWaitSetRunError>
Parameters
ACallback: TCallback<TWaitSetAttachmentId>
Returns
TResult<TWaitSetRunResult, TWaitSetRunError>
Remarks
Important: The TWaitSet only reports that an attachment is ready; it does not consume the notification or data that caused the wake-up. If the callback returns without consuming any pending input, the attachment remains ready and the TWaitSet wakes up again immediately. Repeating this can cause a busy loop and high CPU usage.
For a TListener, consume pending notifications with TListener.TryWait. For a socket or another file-descriptor-based attachment, consume the pending data using its corresponding read or receive API.
WaitAndProcessOnce(TCallback<TWaitSetAttachmentId>)
Waits until an event arrives on the TWaitSet, then collects all events by calling the provided callback with the corresponding TWaitSetAttachmentId and then returns. This makes it ideal to be called in some kind of event-loop.
The provided callback must return TCallbackProgression.Continue to continue the event processing and handle the next event or TCallbackProgression.Stop to return from this call immediately. All unhandled events will be lost forever and the call will return TWaitSetRunResult.StopRequest.
If an interrupt- (SIGINT) or a termination-signal (SIGTERM) was received, it will exit the loop and inform the user with TWaitSetRunResult.Interrupt or TWaitSetRunResult.TerminationRequest.
When no signal was received and all events were handled, it will return TWaitSetRunResult.AllEventsHandled.
function WaitAndProcessOnce(const ACallback: TCallback<TWaitSetAttachmentId>): TResult<TWaitSetRunResult, TWaitSetRunError>
Parameters
ACallback: TCallback<TWaitSetAttachmentId>
Returns
TResult<TWaitSetRunResult, TWaitSetRunError>
Remarks
Important: The TWaitSet only reports that an attachment is ready; it does not consume the notification or data that caused the wake-up. If the callback returns without consuming any pending input, the attachment remains ready and the TWaitSet wakes up again immediately. Repeating this can cause a busy loop and high CPU usage.
For a TListener, consume pending notifications with TListener.TryWait. For a socket or another file-descriptor-based attachment, consume the pending data using its corresponding read or receive API.
WaitAndProcessOnceWithTimeout(TCallback<TWaitSetAttachmentId>, TDuration)
Waits until an event arrives on the TWaitSet or the provided timeout has passed, then collects all events by calling the provided callback with the corresponding TWaitSetAttachmentId and then returns. This makes it ideal to be called in some kind of event-loop.
The provided callback must return TCallbackProgression.Continue to continue the event processing and handle the next event or TCallbackProgression.Stop to return from this call immediately. All unhandled events will be lost forever and the call will return TWaitSetRunResult.StopRequest.
If an interrupt- (SIGINT) or a termination-signal (SIGTERM) was received, it will exit the loop and inform the user with TWaitSetRunResult.Interrupt or TWaitSetRunResult.TerminationRequest.
When no signal was received and all events were handled, it will return TWaitSetRunResult.AllEventsHandled.
function WaitAndProcessOnceWithTimeout(const ACallback: TCallback<TWaitSetAttachmentId>; const ATimeout: TDuration): TResult<TWaitSetRunResult, TWaitSetRunError>
Parameters
ACallback: TCallback<TWaitSetAttachmentId>
ATimeout: TDuration
Returns
TResult<TWaitSetRunResult, TWaitSetRunError>
Remarks
Important: The TWaitSet only reports that an attachment is ready; it does not consume the notification or data that caused the wake-up. If the callback returns without consuming any pending input, the attachment remains ready and the TWaitSet wakes up again immediately. Repeating this can cause a busy loop and high CPU usage.
For a TListener, consume pending notifications with TListener.TryWait. For a socket or another file-descriptor-based attachment, consume the pending data using its corresponding read or receive API.