Skip to content
kibotuPublic

About

Khan is to iOS what androidx.startup is to android.

Topics

Resources

Code of conduct

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

Khan for iOS

Build GitHub Tag Static Badge Static Badge Static Badge

Khan starts your app's modules in parallel while guaranteeing that every initializer runs only after the ones it depends on.

Key Features

  • 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, @MainActor friendly, optional logging hook

Usage

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.

Errors

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.

How to install

Swift Package Manager

Add the dependency to your Package.swift

    products: [
      ...
    ]
    dependencies: [
        .package(url: "https://github.com/kibotu/Khan", from: "<version>"),
    ],
    targets: [
      ...
    ]

Requirements

  • iOS 16.0 or later (macOS 13 for running the tests)
  • Xcode 16.0 or later
  • Swift 6.0 or later

Contributions welcome!

About

Khan is to iOS what androidx.startup is to android.

Topics

Resources

Code of conduct

Stars

2 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages