Skip to content

swift-foundations/swift-clocks-dependencies

Repository files navigation

swift-clocks-dependencies

Development Status

A type-erased clock as a dependency value for swift-dependencies.

The clocks × dependencies integration package: one home for time as a dependency. Consumers reach for @Dependency(\.clock) without their host package carrying clock wiring of its own.

Overview

import Clocks_Dependencies provides @Dependency(\.clock) — a type-erased Clock.`Any`<Duration> resolved through the standard dependency chain:

Context Resolves to Behavior
Live Clock.Continuous() real wall-clock time
Preview Clock.Immediate() no suspension, instant resolution
Test Clock.Immediate() deterministic, no thread hops

Installation

dependencies: [
    .package(url: "https://github.com/swift-foundations/swift-clocks-dependencies.git", branch: "main")
]
.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "Clocks Dependencies", package: "swift-clocks-dependencies")
    ]
)

Quick Start

import Clocks_Dependencies

@Dependency(\.clock) var clock
try await clock.sleep(for: .seconds(1))

Override in tests for controlled time:

@Test(.dependency(\.clock, Clock.`Any`(Clock.Test())))
func timedFeature() async { ... }

License

Licensed under the Apache License, Version 2.0.

About

A type-erased clock as a dependency value for swift-dependencies.

Topics

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages