I was recently writing some verse to play vfx_spawner_device for a few seconds as part of an in game event occurring. I decided to use the opportunity to experiment with the branch version of structured concurrency. I wrote something like the simplified snippet below in the steps to reproduce, but unfortunately the vfx disable call never happens (nor does any code I put inside the branch after the sleep).
Steps to Reproduce
TriggerEvent() : void =
{
# Do stuff before VFX start
# Trigger VFX
if ( VFX_DurationSecs > 0.0 )
{
branch
{
VFX.Enable()
Sleep(VFX_DurationSecs)
VFX.Disable()
}
}
# Do other stuff in parallel with VFX
}
Expected Result
The vfx would start and play for the specified duration and then stop, and the “other stuff in parallel” would occur while the vfx plays.
Observed Result
The vfx starts, and the “other stuff in parallel” does run in parallel but the vfx disable call (or any other code I tried after the sleep) never executes.
This is actually not a bug but is the way “branch” is supposed to behave. Conan Reis discusses this in a video that I just watched (https://www.youtube.com/watch?v=B3WiSgKXsrg). See around the 6:45 mark of the video. Conan specifically says using branch can be tricky and devs need to understand its underlying behavior.
In a nutshell: When branch is used, any branch functions will be cancelled if the function which called them finishes before each branched function finishes. So, the Sleep calls were not exposing a bug, but instead just causing this expected behavior to surface.
I feel this behavior should be better documented on the Verse docs pages.