As a side note, if you’re using this feature be very aware of how C++ lambdas work with variable capture. It’s very easy to capture a stack value by reference that you didn’t intend to that can lead to race conditions!
You can capture specific variables rather than all variables (my preference) and choose whether to capture them by-value or by-reference.
e.g., a simple case:
for (int i = 0; i < SomeStuff.Num(); ++i)
{
auto Future = Async<int>(EAsyncExecution::ThreadPool, &]
{
// "i" has been captured by reference! By the time this thing runs on another thread who knows what it will be
// We could instead use =] but that would copy the SomeStuff array which we probably don't want.
// We could use [i,&SomeStuff] to capture i by value and SomeStuff by reference. That works as long as we guarantee that the array and its contents won't change while these async operations are in-flight.
return DoSlowOperation(SomeStuff*);
});
}