Constructor
new Waitset(condopt)
Create a new Waitset.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
cond |
module:vortexdds.Condition |
<optional> |
null | a condition to attach to the waitset. |
Throws:
-
if the wait set cannot be created or if the optional condition cannot be attached.
Members
conditions :external.Array.<module:vortexdds.Condition>
An array of conditions attached to the waitset.
Type:
- external.Array.<module:vortexdds.Condition>
Methods
attach(cond)
Attach a Condition to this waitset.
Note: if you wish to later detach a from the waitset, you must retain a reference to it.
Parameters:
| Name | Type | Description |
|---|---|---|
cond |
module:vortexdds.Condition | a condition |
Throws:
-
if an error occurs while attempting to attach the condition
delete()
Releases DDS resources associated with the waitset.
Once deleted, the waitset can no longer be used.
Note that DDS resources and memory consumed by waitsets cannot be automatically reclaimed by the NodeJS engine. When your application is finished with a Condition, you may call this method to release these DDS resources.
Note also that Conditions attached to the waitset are NOT reclaimed or deleted by this operation. DDS resources related to Conditions are deleted explicitly by Condition.delete() or implicitly when the containing entity is deleted.
Throws:
-
if an error occurs while attempting to delete the waitset.
detach(cond)
Remove a Condition from the waitset.
Note that detaching a condition does not reclaim any DDS resources associated with it. To reclaim those resouces, you must call Condition.delete().
Parameters:
| Name | Type | Description |
|---|---|---|
cond |
module:vortexdds.Condition | the condition to detach |
Throws:
-
if an error occurs while attempting to detach the condition.
wait(timeoutopt) → {external:Promise.<external:Array.<module:vortexdds.Condition>>}
Asynchronously wait for one or more of the attached conditions to trigger.
When the returned Promise resolves, its value is an array of module:vortexdds.Condition that caused the waitset to trigger.
If a timeout, or other error occurs, then the returned Promise is rejected with a module:vortexdds.DDSError value. If a timeout occurred, then the DDSError.ddsErrCode property will be DDSErrorCode.TIMEOUT.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
timeout |
number | string |
<optional> |
DDSConstants.DDS_INFINITY | a maximum amount of time to wait, in nanoseconds. Represents a 64-bit value. May be a string if the JavaScript numeric representation would result in a loss of precision. |
Returns:
Example
const dds = require('vortexdds');
const ws = new dds.Waitset();
// ... use ws.attach(conditions)
const SEC_TO_NS = 10 ^ 9;
ws.wait(10 * SEC_TO_NS)
.then(triggeredConds => {
for(const cond of triggeredConds) {
// 'cond' was triggered, do something
// about it
}
})
.catch(err => {
if(err.ddsErrorCode === dds.DDSErrorCode.TIMEOUT) {
// a timeout
} else {
// something more serious
}
})
.then(_ => {
// finally, do any cleanup required, regardless
// of whether the promise resolved or rejected.
});