Vala markets itself as a C#-like language with near-C performance, aimed at Gnome development. It borrows async and await semantics from C#, and many I/O library calls exist in async form, including make_directory_async.

create_directory_with_parents_async.vala
async void create_directory_with_parents_async(File file, Cancellable? cancellable = null) throws Error {
    var to_create = new File[0];
    var? current_target = file;
    while(current_target != null) {
        try {
            yield current_target.make_directory_async(Priority.DEFAULT, cancellable);
        } catch(IOError.NOT_FOUND e) {
            to_create += current_target;
            current_target = current_target.get_parent();
            continue;
        } catch(IOError.EXISTS e) {
            break;
        }
        break;
    }
}

What the core library does not offer is an async version of create_directory_with_parents, the recursive mkdir helper. Author Remy Porter suspects the omission is deliberate, since recursive directory creation involves race conditions that are solvable but tricky.

A reader named Eri needed the missing function and wrote it. The first loop tries to create the leaf directory. On IOError.NOT_FOUND it walks up to the parent, appending each failed target to an array, until it hits an existing directory, succeeds, or runs out of parents. A second loop then iterates the array backwards, creating the shortest missing paths first and swallowing IOError.EXISTS in case another process got there first.

The implementation relies on exceptions for flow control, which makes tracing the first loop unpleasant. Eri notes the irony that the C mechanism Vala wraps uses plain error codes, which would have been friendlier here. A reworked loop with reordered catch clauses reads slightly better but stays the same approach.

Porter grants absolution. The code patches a genuine gap in the core library and handles the race condition correctly. His advice: hide it in a box and never touch the implementation again, except to delete it once Vala ships the real thing.