# CodeSOD: Asynchronous Directories

DevFeed: [CodeSOD: Asynchronous Directories](<https://devfeed.tech/articles/codesod-asynchronous-directories-28505.md>)

Original publisher: [Read original article](<https://thedailywtf.com/articles/asynchronous-directories>)

Author: Remy Porter

Published: 2026-09-09T06:30:00Z

Content type: article

Language: en

Sources: [The Daily WTF](<https://devfeed.tech/sources/the-daily-wtf.md>)

Topics: [Vala](<https://devfeed.tech/topics/vala.md>), [async/await](<https://devfeed.tech/topics/async-await.md>), [Library](<https://devfeed.tech/topics/library.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [async](<https://devfeed.tech/tags/async.md>), [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [await](<https://devfeed.tech/tags/await.md>), [codesod](<https://devfeed.tech/tags/codesod.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [filesystem](<https://devfeed.tech/tags/filesystem.md>), [writing-code](<https://devfeed.tech/tags/writing-code.md>)

## AI overview

This article examines implementing an asynchronous version of Vala's directory-creation method when the core library provides only a synchronous version. The proposed function walks up the directory tree, then creates missing directories in reverse order, using exceptions for control flow.

## Source excerpt

Eri has a mix of a "true confession" and a "wait, really?" today. The programming language Vala bills itself as a C# like language that compiles into something pretty close to C performance, designed specifically for writing code against Gnome and its associated libraries. One of the C#-isms in brings in is async/await type semantics. You can yield someAsyncFunction(), which returns control to the caller, allowing it to proceed until the yielded function returns an actual value. Because it has asynchronous functions, many library functions for handling I/O are already async. So you can make_directory_async, which yields control so you can keep executing while waiting for the filesystem to make your directory. There are also synchronous versions of those methods. And then there's create_directory_with_parents, which will create a chain of directories for you. That's the synchronous version, and Vala's core library has decided not to provide an asynchronous version of it, which is my "wait, really?" I suspect it's really about the race conditions involved and the risks of things going wrong while doing it asynchronously; all solvable problems, but tricky ones to solve. But it's the problem Eri had, and this is their solution: /// Note: does not throw if target already exists 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; } for (int i = to_create.length - 1; i >= 0; --i) { try { yield to_create[i].make_directory_async(Priority.DEFAULT, cancellable); } catch(IOError.EXISTS e) { // Created by another process } } } If I'm reading this correctly, we start by trying to create the full path to