Cancel Wait Call

<< Click to Display Table of Contents >>

Navigation:  Migration Guide for the Acquisition Stacks > CVB++ >

Cancel Wait Call

The cancellation token gives the possibility to cancel individual wait calls instead of the whole acquisition. Restarting the whole acquisition takes much longer, than to simply call wait functions again. A use case for example would be if an external stop signal is received by the application, the fastest reaction to stop the acquisition and to restart it, would be to abort the wait function with a cancellation token. The wait call returns with the wait status abort in this case. The token itself can be checked if it has been canceled.

 

Code Example

3rd generation stack

1

2

3

4

5

6

7

8

9

CancellationTokenSource source;

auto token = source.Token();

CompositePtr composite;

WaitStatus waitStatus;

NodeMapEnumerator enumerator;

std::tie(composite, waitStatus, enumerator) =

 stream->WaitFor(std::chrono::milliseconds(10), *token);

source.Cancel();

token->IsCanceled();

(1) Create a cancellation token source object, which provides tokens and the signal to cancel.

(2) Get a cancellation token.

(6) Pass the cancellation token to the wait function.

(8) Cancel the wait function by using the cancellation token.

(9) Returns, whether or not the cancellation token has been canceled.