aven 0.1.16

Local-first task manager CLI and sync server
Documentation
import AvenUniFFI
import Dispatch

public final class RustWorker: @unchecked Sendable {
    private let queue: DispatchQueue

    public init(label: String = "com.raine.aven.ios-proof.rust") {
        queue = DispatchQueue(label: label)
    }

    public func run<T: Sendable>(
        _ operation: @escaping @Sendable () throws -> T
    ) async throws -> T {
        try await withCheckedThrowingContinuation { continuation in
            queue.async {
                do {
                    try continuation.resume(returning: operation())
                } catch {
                    continuation.resume(throwing: error)
                }
            }
        }
    }

    public func withClient<T: Sendable>(
        at databasePath: String,
        _ operation: @escaping @Sendable (AvenClient) throws -> T
    ) async throws -> T {
        try await run {
            let client = try AvenClient.open(path: databasePath)
            return try operation(client)
        }
    }
}