Thread Conditions
Thread Conditional Wrap
There are times when you want to turn off or disable something running when a condition occurs. An example of this would be to only run a Coordinator when there is a known network connection available.
This is made possible by a ThreadCondition
:
Let's take a look at what's happening:
The method itself is thread blocking, so it won't return out until the
parentToken
is cancelled.The first callback supplies a
childToken
to be used in any method that returns a Task.This could be your own Task or "async" method.
The second callback should return
TRUE
if the method should be running, or start for the first time.If it returns
FALSE
, the condition will cancel thechildToken
and await theTask
from the first callback.
The final parameter you can supply is how often this check occurs.
You may also use Behavior Tree's in the condition callback. This will process the tree on every run.
Running the demo
In this example, flipping off the Wi-Fi radio of your development box will stop the coordinator from receiving new messages. Turning it back on will start the coordinator again.
Last updated