Skip to content

Commit d1c5531

Browse files
authored
feat: add scheduling with Clock API support (#9)
* feat: add scheduling with Clock API support * refactor: add clock API tests and improve test parallelization * wip: fix compiler condition missing * wip: fix compiler condition missing * wip: manually start operation on non-`Darwin` platforms * wip: use ubuntu runner for codecov upload * wip: check for operation cancellation with expectation * wip: remove `OperationQueue` usage for non-macOS platform * wip: add tolerance for clock waits
1 parent 9f7f243 commit d1c5531

25 files changed

+2638
-1335
lines changed

.github/workflows/main.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ jobs:
4949
uses: SwiftyLab/ci/.github/workflows/swift-package.yml@main
5050
secrets: inherit
5151
with:
52-
codecov-swift: '5.6'
53-
codecov-os: macos-12
52+
codecov-swift: '5.7'
53+
codecov-os: ubuntu-latest
5454
matrix: >
5555
{
5656
"include": [
5757
{
58-
"os": "macos-12",
59-
"xcode": "latest-stable",
60-
"swift": "5.6"
58+
"os": "ubuntu-latest",
59+
"swift": "5.7"
6160
},
6261
{
6362
"os": "ubuntu-latest",

AsyncObjects.xcodeproj/project.pbxproj

+469-452
Large diffs are not rendered by default.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![Swift](https://img.shields.io/badge/Swift-5.6+-orange)](https://img.shields.io/badge/Swift-5-DE5D43)
88
[![Platforms](https://img.shields.io/badge/Platforms-all-sucess)](https://img.shields.io/badge/Platforms-all-sucess)
99
[![CI/CD](https://github.com/SwiftyLab/AsyncObjects/actions/workflows/main.yml/badge.svg?event=push)](https://github.com/SwiftyLab/AsyncObjects/actions/workflows/main.yml)
10-
[![Maintainability](https://api.codeclimate.com/v1/badges/37183c809818826c1bcf/maintainability)](https://codeclimate.com/github/SwiftyLab/AsyncObjects/maintainability)
10+
[![CodeFactor](https://www.codefactor.io/repository/github/swiftylab/asyncobjects/badge)](https://www.codefactor.io/repository/github/swiftylab/asyncobjects)
1111
[![codecov](https://codecov.io/gh/SwiftyLab/AsyncObjects/branch/main/graph/badge.svg?token=jKxMv5oFeA)](https://codecov.io/gh/SwiftyLab/AsyncObjects)
1212
<!-- [![CodeQL](https://github.com/SwiftyLab/AsyncObjects/actions/workflows/codeql-analysis.yml/badge.svg?event=schedule)](https://github.com/SwiftyLab/AsyncObjects/actions/workflows/codeql-analysis.yml) -->
1313

Sources/AsyncObjects/AsyncCountdownEvent.swift

+11-8
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import OrderedCollections
1313
/// in the sense that instead of restricting access to a resource,
1414
/// it notifies when the resource usage is idle or inefficient.
1515
///
16-
/// You can indicate high priority usage of resource by using ``increment(by:)`` method,
17-
/// and indicate free of resource by calling ``signal(repeat:)`` or ``signal()`` methods.
18-
/// For low priority resource usage or detect resource idling use ``wait()`` method
19-
/// or its timeout variation ``wait(forNanoseconds:)``:
16+
/// You can indicate high priority usage of resource by using ``increment(by:file:function:line:)``
17+
/// method, and indicate free of resource by calling ``signal(repeat:file:function:line:)``
18+
/// or ``signal(file:function:line:)`` methods.
19+
/// For low priority resource usage or detect resource idling use ``wait(file:function:line:)``
20+
/// method or its timeout variation ``wait(until:tolerance:clock:file:function:line:)``:
2021
///
2122
/// ```swift
2223
/// // create event with initial count and count down limit
@@ -63,8 +64,9 @@ public actor AsyncCountdownEvent: AsyncObject, ContinuableCollection {
6364
public var currentCount: UInt
6465
/// Initial count of the countdown when count started.
6566
///
66-
/// Can be changed after initialization
67-
/// by using ``reset(to:)`` method.
67+
/// Can be changed after initialization by using
68+
/// ``reset(to:file:function:line:)``
69+
/// method.
6870
public var initialCount: UInt
6971
/// Indicates whether countdown event current count is within ``limit``.
7072
///
@@ -180,8 +182,9 @@ public actor AsyncCountdownEvent: AsyncObject, ContinuableCollection {
180182

181183
/// Increments the countdown event current count by the specified value.
182184
///
183-
/// Unlike the ``wait()`` method count is reflected immediately.
184-
/// Use this to indicate usage of resource from high priority tasks.
185+
/// Unlike the ``wait(file:function:line:)`` method
186+
/// count is reflected immediately. Use this to indicate usage of
187+
/// resource from high priority tasks.
185188
///
186189
/// - Parameter count: The value by which to increase ``currentCount``.
187190
public nonisolated func increment(

Sources/AsyncObjects/AsyncEvent.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import Foundation
88
///
99
/// An async event suspends tasks if current state is non-signaled and resumes execution when event is signalled.
1010
///
11-
/// You can signal event by calling the ``signal()`` method and reset signal by calling ``reset()``.
12-
/// Wait for event signal by calling ``wait()`` method or its timeout variation ``wait(forNanoseconds:)``:
11+
/// You can signal event by calling the ``signal(file:function:line:)``
12+
/// method and reset signal by calling ``reset(file:function:line:)``.
13+
/// Wait for event signal by calling ``wait(file:function:line:)``
14+
/// method or its timeout variation ``wait(until:tolerance:clock:file:function:line:)``:
1315
///
1416
/// ```swift
1517
/// // create event with initial state (signalled or not)
@@ -105,7 +107,11 @@ public actor AsyncEvent: AsyncObject, ContinuableCollection {
105107
/// - line: The line reset originates from (there's usually no need to pass it
106108
/// explicitly as it defaults to `#line`).
107109
@Sendable
108-
public nonisolated func reset() {
110+
public nonisolated func reset(
111+
file: String = #fileID,
112+
function: String = #function,
113+
line: UInt = #line
114+
) {
109115
Task { await resetEvent() }
110116
}
111117

Sources/AsyncObjects/AsyncSemaphore.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import OrderedCollections
1111
/// An async semaphore is an efficient implementation of a traditional counting semaphore.
1212
/// Unlike traditional semaphore, async semaphore suspends current task instead of blocking threads.
1313
///
14-
/// You increment a semaphore count by calling the ``signal()`` method
15-
/// and decrement a semaphore count by calling ``wait()`` method
16-
/// or its timeout variation ``wait(forNanoseconds:)``:
14+
/// You increment a semaphore count by calling the ``signal(file:function:line:)`` method
15+
/// and decrement a semaphore count by calling ``wait(file:function:line:)`` method
16+
/// or its timeout variation ``wait(until:tolerance:clock:file:function:line:)``:
1717
///
1818
/// ```swift
1919
/// // create limiting concurrent access count

0 commit comments

Comments
 (0)