I am confronted to a simple example of couroutine in a UWP application but cannot find out how to achieve it.
Here is my purpose: given a path on a disk and a base folder, I want to create the folder hierarchy associated. for example: base folder: "c:\test\" path: "test1\test2\test3"
my purpose is to create the folders test1, test2 and test3 so we have following folder structure: c:\test\test1\test2\test3\
Here is what I did so far: I parse the path so I have its different components (test1, test2 and test3) in an array (subfolders in the following example)
Windows::Storage::StorageFolder^ current_storage_folder = base_folder;
for (auto& subfolder : subfolders)
{
if (!subfolder.empty())
{
Windows::Storage::StorageFolder^ next_storage_folder = (Windows::Storage::StorageFolder^)co_await current_storage_folder->TryGetItemAsync(subfolder);
if (next_storage_folder == nullptr)
{
next_storage_folder = co_await current_storage_folder->CreateFolderAsync(subfolder);
}
current_storage_folder = next_storage_folder;
}
}
The output I get is wrong, as I have test1 which is created, sometimes test2. however, result cannot be predicted.
I think my understanding of co_await is wrong, as I expect each co_await call to finish before getting to the next call, which do not seem to be the case.