The Daily WTF
Follow
CodeSOD: Asynchronous Directories
Vala is a programming language designed for Gnome with C# like features and near C performance. It supports asynchronous programming with async/await semantics, allowing functions to yield control. Many I/O library functions in Vala are asynchronous, such as make_directory_async. However, the core library lacks an asynchronous version of create_directory_with_parents, which synchronously creates directory chains. This omission is likely due to the complexity of handling race conditions asynchronously. The author, Eri, encountered this problem and implemented a custom asynchronous solution. Eri's initial approach involves attempting to create directories from the leaf node upwards, collecting missing parents in an array. It then iterates backwards through this array to create the directories. This method is considered inelegant as it uses exception handling for control flow. Eri acknowledges the difficulty of the problem, particularly managing asynchronous race conditions. A slightly improved version of the main loop is presented, but the approach remains complex. Despite its awkwardness, Eri's solution effectively addresses the missing library functionality. The author suggests the implemented function should be hidden away once it works correctly.