Search code examples
hacklang

How to place an if statement inside a concurrent block in Hacklang?


Say I have 3 asynchronous functions A,B, and C. I want to run them concurrently inside a concurrent block, but for one of the functions I want to check a condition. I'm looking for the following behaviour:

concurrent {
    await A(...);
    await B(...);
    if ($some_condition) {
        await C(...);
    }
}

Solution

  • Use an async block:

    concurrent {
        await A(...);
        await B(...);
        await async {
            if ($some_condition) {
                await C(...);
            }
        };
    }