Skip to content

Commit 9e69dbb

Browse files
committed
doc: add docC calatalog for library
1 parent 92c5810 commit 9e69dbb

11 files changed

+357
-195
lines changed

.gitignore

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ DerivedData/
2222
*.perspectivev3
2323
!default.perspectivev3
2424

25+
# OS generated files #
26+
######################
27+
.DS_Store
28+
.DS_Store?
29+
._*
30+
.Spotlight-V100
31+
.Trashes
32+
ehthumbs.db
33+
Thumbs.db
34+
2535
## Obj-C/Swift specific
2636
*.hmap
2737

@@ -40,7 +50,7 @@ playground.xcworkspace
4050
Packages/
4151
Package.pins
4252
Package.resolved
43-
*.xcodeproj
53+
# *.xcodeproj
4454

4555
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
4656
# hence it is not needed unless you have added a package configuration file to your project
@@ -66,6 +76,12 @@ Package.resolved
6676

6777
Carthage/Build/
6878

79+
# Add Xcode project related files required by Carthage
80+
AsyncObject.xcodeproj/*
81+
!AsyncObject.xcodeproj/*.pbxproj
82+
!AsyncObject.xcodeproj/*.plist
83+
!AsyncObject.xcodeproj/xcshareddata
84+
6985
# Accio dependency management
7086
Dependencies/
7187
.accio/
@@ -88,3 +104,119 @@ fastlane/test_output
88104
# https://github.com/johnno1962/injectionforxcode
89105

90106
iOSInjectionProject/
107+
108+
# DocC
109+
.netrc
110+
.docc-build
111+
*.doccarchive*
112+
113+
# Built Products
114+
*.xcframework*
115+
*.zip
116+
*.tar*
117+
118+
## Node-Js ignores
119+
# Logs
120+
logs
121+
*.log
122+
npm-debug.log*
123+
yarn-debug.log*
124+
yarn-error.log*
125+
lerna-debug.log*
126+
127+
# Diagnostic reports (https://nodejs.org/api/report.html)
128+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
129+
130+
# Runtime data
131+
pids
132+
*.pid
133+
*.seed
134+
*.pid.lock
135+
136+
# Directory for instrumented libs generated by jscoverage/JSCover
137+
lib-cov
138+
139+
# Coverage directory used by tools like istanbul
140+
coverage
141+
*.lcov
142+
143+
# nyc test coverage
144+
.nyc_output
145+
146+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
147+
.grunt
148+
149+
# Bower dependency directory (https://bower.io/)
150+
bower_components
151+
152+
# node-waf configuration
153+
.lock-wscript
154+
155+
# Compiled binary addons (https://nodejs.org/api/addons.html)
156+
build/Release
157+
158+
# Dependency directories
159+
node_modules/
160+
jspm_packages/
161+
162+
# TypeScript v1 declaration files
163+
typings/
164+
165+
# TypeScript cache
166+
*.tsbuildinfo
167+
168+
# Optional npm cache directory
169+
.npm
170+
171+
# Optional eslint cache
172+
.eslintcache
173+
174+
# Microbundle cache
175+
.rpt2_cache/
176+
.rts2_cache_cjs/
177+
.rts2_cache_es/
178+
.rts2_cache_umd/
179+
180+
# Optional REPL history
181+
.node_repl_history
182+
183+
# Output of 'npm pack'
184+
*.tgz
185+
186+
# Yarn Integrity file
187+
.yarn-integrity
188+
189+
# dotenv environment variables file
190+
.env
191+
.env.test
192+
193+
# parcel-bundler cache (https://parceljs.org/)
194+
.cache
195+
196+
# Next.js build output
197+
.next
198+
199+
# Nuxt.js build / generate output
200+
.nuxt
201+
dist
202+
203+
# Gatsby files
204+
.cache/
205+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
206+
# https://nextjs.org/blog/next-9-1#public-directory-support
207+
# public
208+
209+
# vuepress build output
210+
.vuepress/dist
211+
212+
# Serverless directories
213+
.serverless/
214+
215+
# FuseBox cache
216+
.fusebox/
217+
218+
# DynamoDB Local files
219+
.dynamodb/
220+
221+
# TernJS port file
222+
.tern-port

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"explorer.excludeGitIgnore": true,
2+
"files.exclude": {
3+
"**/.build": true,
4+
"**/.swiftpm": true,
5+
"**/.docc-build": true,
6+
"**/node_modules": true,
7+
"Package.resolved": true
8+
}
39
}

Sources/AsyncObject/AsyncMutex.swift

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ``AsyncObject``
2+
3+
Several synchronization primitives introduced to aid in modern swift concurrency. The primitives are very similar to those used in other operating systems including mutexes, condition variables, shared/exclusive locks, and semaphores.
4+
5+
## Overview
6+
7+
Several synchronization primitives introduced to aid in modern swift concurrency. The primitives are very similar to those used in other operating systems including mutexes, condition variables, shared/exclusive locks, and semaphores.
8+
9+
## Topics
10+
11+
### Synchronization Primitives
12+
13+
- ``AsyncSemaphore``

Sources/AsyncObject/AsyncSemaphore.swift

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,64 @@
11
import Foundation
22
import OrderedCollections
33

4-
actor AsyncSemaphore {
4+
/// An object that controls access to a resource across multiple task contexts through use of a traditional counting semaphore.
5+
///
6+
/// An async semaphore is an efficient implementation of a traditional counting semaphore.
7+
/// Unlike traditional semaphore, async semaphore suspends current task instead of blocking threads.
8+
///
9+
/// You increment a semaphore count by calling the ``signal()`` method
10+
/// and decrement a semaphore count by calling ``wait()`` method
11+
/// or its timeout variation ``wait(forNanoseconds:)``.
12+
public actor AsyncSemaphore {
13+
/// The suspended tasks continuation type.
514
private typealias Continuation = UnsafeContinuation<Void, Error>
15+
/// The continuations stored with an associated key for all the suspended task that are waitig for access to resource.
616
private var continuations: OrderedDictionary<UUID, Continuation> = [:]
17+
/// Pool size for concurrent resource access.
18+
/// Has value provided during initialization incremented by one.
719
private var limit: UInt
20+
/// Current count of semaphore.
21+
/// Can have maximum value upto `limit`.
822
private var count: Int
923

24+
/// Add continuation with the provided key in `continuations` map.
25+
///
26+
/// - Parameters:
27+
/// - continuation: The `continuation` to add.
28+
/// - key: The key in the map.
1029
private func addContinuation(
1130
_ continuation: Continuation,
1231
withKey key: UUID
1332
) {
1433
continuations[key] = continuation
1534
}
1635

36+
/// Remove continuation associated with provided key
37+
/// from `continuations` map.
38+
///
39+
/// - Parameter key: The key in the map.
1740
private func removeContinuation(withKey key: UUID) {
1841
continuations.removeValue(forKey: key)
1942
}
2043

44+
/// Creates new counting semaphore with an initial value.
45+
/// By default, initial value is zero.
46+
///
47+
/// Passing zero for the value is useful for when two threads need to reconcile the completion of a particular event.
48+
/// Passing a value greater than zero is useful for managing a finite pool of resources, where the pool size is equal to the value.
49+
///
50+
/// - Parameter count: The starting value for the semaphore.
51+
/// - Returns: The newly created semaphore.
2152
public init(value count: UInt = 0) {
2253
self.limit = count + 1
2354
self.count = Int(limit)
2455
}
2556

57+
/// Signals (increments) a semaphore.
58+
///
59+
/// Increment the counting semaphore.
60+
/// If the previous value was less than zero,
61+
/// current task is resumed from suspension.
2662
public func signal() {
2763
guard count < limit else { return }
2864
count += 1
@@ -31,6 +67,10 @@ actor AsyncSemaphore {
3167
continuation.resume()
3268
}
3369

70+
/// Waits for, or decrements, a semaphore.
71+
///
72+
/// Decrement the counting semaphore. If the resulting value is less than zero,
73+
/// current task is suspended until a signal occurs.
3474
public func wait() async {
3575
count -= 1
3676
if count > 0 { return }
@@ -50,6 +90,13 @@ actor AsyncSemaphore {
5090
}
5191
}
5292

93+
/// Waits for within the duration, or decrements, a semaphore.
94+
///
95+
/// Decrement the counting semaphore. If the resulting value is less than zero,
96+
/// current task is suspended until a signal occurs or timeout duration completes.
97+
///
98+
/// - Parameter duration: The duration in nano seconds to wait until.
99+
/// - Returns: The result indicating whether wait completed or timed out.
53100
@discardableResult
54101
public func wait(
55102
forNanoseconds duration: UInt64

0 commit comments

Comments
 (0)