Skip to content

Commit

Permalink
feat: add scheduling with Clock API support (#9)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
soumyamahunt committed Dec 4, 2022
1 parent 9f7f243 commit d1c5531
Show file tree
Hide file tree
Showing 25 changed files with 2,638 additions and 1,335 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ jobs:
uses: SwiftyLab/ci/.github/workflows/swift-package.yml@main
secrets: inherit
with:
codecov-swift: '5.6'
codecov-os: macos-12
codecov-swift: '5.7'
codecov-os: ubuntu-latest
matrix: >
{
"include": [
{
"os": "macos-12",
"xcode": "latest-stable",
"swift": "5.6"
"os": "ubuntu-latest",
"swift": "5.7"
},
{
"os": "ubuntu-latest",
Expand Down
921 changes: 469 additions & 452 deletions AsyncObjects.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Swift](https://img.shields.io/badge/Swift-5.6+-orange)](https://img.shields.io/badge/Swift-5-DE5D43)
[![Platforms](https://img.shields.io/badge/Platforms-all-sucess)](https://img.shields.io/badge/Platforms-all-sucess)
[![CI/CD](https://github.com/SwiftyLab/AsyncObjects/actions/workflows/main.yml/badge.svg?event=push)](https://github.com/SwiftyLab/AsyncObjects/actions/workflows/main.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/37183c809818826c1bcf/maintainability)](https://codeclimate.com/github/SwiftyLab/AsyncObjects/maintainability)
[![CodeFactor](https://www.codefactor.io/repository/github/swiftylab/asyncobjects/badge)](https://www.codefactor.io/repository/github/swiftylab/asyncobjects)
[![codecov](https://codecov.io/gh/SwiftyLab/AsyncObjects/branch/main/graph/badge.svg?token=jKxMv5oFeA)](https://codecov.io/gh/SwiftyLab/AsyncObjects)
<!-- [![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) -->

Expand Down
19 changes: 11 additions & 8 deletions Sources/AsyncObjects/AsyncCountdownEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import OrderedCollections
/// in the sense that instead of restricting access to a resource,
/// it notifies when the resource usage is idle or inefficient.
///
/// You can indicate high priority usage of resource by using ``increment(by:)`` method,
/// and indicate free of resource by calling ``signal(repeat:)`` or ``signal()`` methods.
/// For low priority resource usage or detect resource idling use ``wait()`` method
/// or its timeout variation ``wait(forNanoseconds:)``:
/// You can indicate high priority usage of resource by using ``increment(by:file:function:line:)``
/// method, and indicate free of resource by calling ``signal(repeat:file:function:line:)``
/// or ``signal(file:function:line:)`` methods.
/// For low priority resource usage or detect resource idling use ``wait(file:function:line:)``
/// method or its timeout variation ``wait(until:tolerance:clock:file:function:line:)``:
///
/// ```swift
/// // create event with initial count and count down limit
Expand Down Expand Up @@ -63,8 +64,9 @@ public actor AsyncCountdownEvent: AsyncObject, ContinuableCollection {
public var currentCount: UInt
/// Initial count of the countdown when count started.
///
/// Can be changed after initialization
/// by using ``reset(to:)`` method.
/// Can be changed after initialization by using
/// ``reset(to:file:function:line:)``
/// method.
public var initialCount: UInt
/// Indicates whether countdown event current count is within ``limit``.
///
Expand Down Expand Up @@ -180,8 +182,9 @@ public actor AsyncCountdownEvent: AsyncObject, ContinuableCollection {

/// Increments the countdown event current count by the specified value.
///
/// Unlike the ``wait()`` method count is reflected immediately.
/// Use this to indicate usage of resource from high priority tasks.
/// Unlike the ``wait(file:function:line:)`` method
/// count is reflected immediately. Use this to indicate usage of
/// resource from high priority tasks.
///
/// - Parameter count: The value by which to increase ``currentCount``.
public nonisolated func increment(
Expand Down
12 changes: 9 additions & 3 deletions Sources/AsyncObjects/AsyncEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import Foundation
///
/// An async event suspends tasks if current state is non-signaled and resumes execution when event is signalled.
///
/// You can signal event by calling the ``signal()`` method and reset signal by calling ``reset()``.
/// Wait for event signal by calling ``wait()`` method or its timeout variation ``wait(forNanoseconds:)``:
/// You can signal event by calling the ``signal(file:function:line:)``
/// method and reset signal by calling ``reset(file:function:line:)``.
/// Wait for event signal by calling ``wait(file:function:line:)``
/// method or its timeout variation ``wait(until:tolerance:clock:file:function:line:)``:
///
/// ```swift
/// // create event with initial state (signalled or not)
Expand Down Expand Up @@ -105,7 +107,11 @@ public actor AsyncEvent: AsyncObject, ContinuableCollection {
/// - line: The line reset originates from (there's usually no need to pass it
/// explicitly as it defaults to `#line`).
@Sendable
public nonisolated func reset() {
public nonisolated func reset(
file: String = #fileID,
function: String = #function,
line: UInt = #line
) {
Task { await resetEvent() }
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/AsyncObjects/AsyncSemaphore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import OrderedCollections
/// An async semaphore is an efficient implementation of a traditional counting semaphore.
/// Unlike traditional semaphore, async semaphore suspends current task instead of blocking threads.
///
/// You increment a semaphore count by calling the ``signal()`` method
/// and decrement a semaphore count by calling ``wait()`` method
/// or its timeout variation ``wait(forNanoseconds:)``:
/// You increment a semaphore count by calling the ``signal(file:function:line:)`` method
/// and decrement a semaphore count by calling ``wait(file:function:line:)`` method
/// or its timeout variation ``wait(until:tolerance:clock:file:function:line:)``:
///
/// ```swift
/// // create limiting concurrent access count
Expand Down

0 comments on commit d1c5531

Please sign in to comment.