Khan starts your app's modules in parallel while guaranteeing that every initializer runs only after the ones it depends on.
- Parallel start-up: each initializer launches the moment its dependencies succeed
- Graph validated up front: missing dependencies and cycles (with the full path) throw from
init - Failure isolation: if an initializer throws, its dependents are skipped, everything else still runs
- Swift concurrency native,
@MainActorfriendly, optional logging hook
enum ConfigInitializer: Initializer {
static func embark() async throws { /* load config */ }
}
enum DatabaseInitializer: Initializer {
static let dependencies: [Initializer.Type] = [ConfigInitializer.self]
@MainActor static func embark() async throws { /* open database */ }
}
let khan = try Khan(
initializers: [ConfigInitializer.self, DatabaseInitializer.self],
logger: { print("[Khan]", $0) }
)
try await khan.conquer()Every dependency must be registered too, otherwise Khan.init throws KhanError.missingDependency.
conquer() throws KhanError.failed(_:skipped:) after all runnable work has settled. It lists each failed initializer with its error, and the initializers that never ran because a dependency failed.
Add the dependency to your Package.swift
products: [
...
]
dependencies: [
.package(url: "https://github.com/kibotu/Khan", from: "<version>"),
],
targets: [
...
]- iOS 16.0 or later (macOS 13 for running the tests)
- Xcode 16.0 or later
- Swift 6.0 or later
Contributions welcome!