Skip to content

Commit eb2d589

Browse files
committed
Implement Concurrency package
1 parent b0eddab commit eb2d589

16 files changed

Lines changed: 680 additions & 1 deletion

File tree

.swiftformat

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Stream rules
2+
3+
--swiftversion 5.3
4+
5+
# Use 'swiftformat --options' to list all of the possible options
6+
7+
--header "\nConcurrency\nCopyright © {created.year} Space Code. All rights reserved.\n//"
8+
9+
--enable blankLinesBetweenScopes
10+
--enable blankLinesAtStartOfScope
11+
--enable blankLinesAtEndOfScope
12+
--enable blankLinesAroundMark
13+
--enable anyObjectProtocol
14+
--enable consecutiveBlankLines
15+
--enable consecutiveSpaces
16+
--enable duplicateImports
17+
--enable elseOnSameLine
18+
--enable emptyBraces
19+
--enable initCoderUnavailable
20+
--enable leadingDelimiters
21+
--enable numberFormatting
22+
--enable preferKeyPath
23+
--enable redundantBreak
24+
--enable redundantExtensionACL
25+
--enable redundantFileprivate
26+
--enable redundantGet
27+
--enable redundantInit
28+
--enable redundantLet
29+
--enable redundantLetError
30+
--enable redundantNilInit
31+
--enable redundantObjc
32+
--enable redundantParens
33+
--enable redundantPattern
34+
--enable redundantRawValues
35+
--enable redundantReturn
36+
--enable redundantSelf
37+
--enable redundantVoidReturnType
38+
--enable semicolons
39+
--enable sortedImports
40+
--enable sortedSwitchCases
41+
--enable spaceAroundBraces
42+
--enable spaceAroundBrackets
43+
--enable spaceAroundComments
44+
--enable spaceAroundGenerics
45+
--enable spaceAroundOperators
46+
--enable spaceInsideBraces
47+
--enable spaceInsideBrackets
48+
--enable spaceInsideComments
49+
--enable spaceInsideGenerics
50+
--enable spaceInsideParens
51+
--enable strongOutlets
52+
--enable strongifiedSelf
53+
--enable todos
54+
--enable trailingClosures
55+
--enable unusedArguments
56+
--enable void
57+
--enable markTypes
58+
--enable isEmpty
59+
60+
# format options
61+
62+
--wraparguments before-first
63+
--wrapcollections before-first
64+
--maxwidth 140

.swiftlint.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
excluded:
2+
- Tests
3+
- Package.swift
4+
- .build
5+
6+
# Rules
7+
8+
disabled_rules:
9+
- trailing_comma
10+
- todo
11+
- opening_brace
12+
13+
opt_in_rules: # some rules are only opt-in
14+
- anyobject_protocol
15+
- array_init
16+
- attributes
17+
- closure_body_length
18+
- closure_end_indentation
19+
- closure_spacing
20+
- collection_alignment
21+
- conditional_returns_on_newline
22+
- contains_over_filter_count
23+
- contains_over_filter_is_empty
24+
- contains_over_first_not_nil
25+
- contains_over_range_nil_comparison
26+
- convenience_type
27+
- discouraged_object_literal
28+
- discouraged_optional_boolean
29+
- empty_collection_literal
30+
- empty_count
31+
- empty_string
32+
- empty_xctest_method
33+
- enum_case_associated_values_count
34+
- explicit_init
35+
- fallthrough
36+
- fatal_error_message
37+
- file_name
38+
- file_types_order
39+
- first_where
40+
- flatmap_over_map_reduce
41+
- force_unwrapping
42+
- ibinspectable_in_extension
43+
- identical_operands
44+
- implicit_return
45+
- inert_defer
46+
- joined_default_parameter
47+
- last_where
48+
- legacy_multiple
49+
- legacy_random
50+
- literal_expression_end_indentation
51+
- lower_acl_than_parent
52+
- multiline_arguments
53+
- multiline_function_chains
54+
- multiline_literal_brackets
55+
- multiline_parameters
56+
- multiline_parameters_brackets
57+
- no_space_in_method_call
58+
- operator_usage_whitespace
59+
- optional_enum_case_matching
60+
- orphaned_doc_comment
61+
- overridden_super_call
62+
- override_in_extension
63+
- pattern_matching_keywords
64+
- prefer_self_type_over_type_of_self
65+
- prefer_zero_over_explicit_init
66+
- prefixed_toplevel_constant
67+
- private_action
68+
- prohibited_super_call
69+
- quick_discouraged_call
70+
- quick_discouraged_focused_test
71+
- quick_discouraged_pending_test
72+
- reduce_into
73+
- redundant_nil_coalescing
74+
- redundant_objc_attribute
75+
- redundant_type_annotation
76+
- required_enum_case
77+
- single_test_class
78+
- sorted_first_last
79+
- sorted_imports
80+
- static_operator
81+
- strict_fileprivate
82+
- switch_case_on_newline
83+
- toggle_bool
84+
- unavailable_function
85+
- unneeded_parentheses_in_closure_argument
86+
- unowned_variable_capture
87+
- untyped_error_in_catch
88+
- vertical_parameter_alignment_on_call
89+
- vertical_whitespace_closing_braces
90+
- vertical_whitespace_opening_braces
91+
- xct_specific_matcher
92+
- yoda_condition
93+
94+
force_cast: warning
95+
force_try: warning
96+
97+
identifier_name:
98+
excluded:
99+
- id
100+
- URL
101+
102+
analyzer_rules:
103+
- unused_import
104+
- unused_declaration
105+
106+
line_length:
107+
warning: 130
108+
error: 200
109+
110+
type_body_length:
111+
warning: 300
112+
error: 400
113+
114+
file_length:
115+
warning: 500
116+
error: 1200
117+
118+
function_body_length:
119+
warning: 30
120+
error: 50
121+
122+
large_tuple:
123+
error: 3
124+
125+
nesting:
126+
type_level:
127+
warning: 2
128+
statement_level:
129+
warning: 10
130+
131+
132+
type_name:
133+
max_length:
134+
warning: 40
135+
error: 50

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
all: bootstrap
2+
3+
bootstrap: hook
4+
mint bootstrap
5+
6+
hook:
7+
ln -sf ../../hooks/pre-commit .git/hooks/pre-commit
8+
chmod +x .git/hooks/pre-commit
9+
10+
mint:
11+
mint bootstrap
12+
13+
lint:
14+
mint run swiftlint
15+
16+
fmt:
17+
mint run swiftformat Sources Tests
18+
19+
.PHONY: all bootstrap hook mint lint fmt

Mintfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nicklockwood/SwiftFormat@0.47.12
2+
realm/SwiftLint@0.47.1

Package.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// swift-tools-version: 5.7
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "Concurrency",
8+
platforms: [
9+
.macOS(.v10_15),
10+
.iOS(.v13),
11+
.watchOS(.v6),
12+
.tvOS(.v11),
13+
],
14+
products: [
15+
.library(name: "Concurrency", targets: ["Concurrency"]),
16+
.library(name: "TestConcurrency", targets: ["TestConcurrency"]),
17+
],
18+
dependencies: [],
19+
targets: [
20+
.target(name: "Concurrency", dependencies: []),
21+
.target(name: "TestConcurrency", dependencies: ["Concurrency"]),
22+
.testTarget(name: "ConcurrencyTests", dependencies: ["Concurrency"]),
23+
]
24+
)

README.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,91 @@
1-
# concurrency
1+
![concurrency: A collection of concurrency primitives](https://raw.githubusercontent.com/space-code/concurrency/dev/Resources/concurrency.png)
2+
3+
<h1 align="center" style="margin-top: 0px;">concurrency</h1>
4+
5+
<p align="center">
6+
<a href="https://github.com/space-code/concurrency/blob/main/LICENSE"><img alt="Liscence" src="https://img.shields.io/cocoapods/l/service-core.svg?style=flat"></a>
7+
<a href="https://developer.apple.com/"><img alt="Platform" src="https://img.shields.io/badge/platform-ios%20%7C%20osx%20%7C%20watchos%20%7C%20tvos-%23989898"/></a>
8+
<a href="https://developer.apple.com/swift"><img alt="Swift4.2" src="https://img.shields.io/badge/language-Swift5.3-orange.svg"/></a>
9+
</p>
10+
11+
## Description
12+
`concurrency` is a collection of concurrency primitives which helps increase testability
13+
14+
- [Usage](#usage)
15+
- [Requirements](#requirements)
16+
- [Installation](#installation)
17+
- [Communication](#communication)
18+
- [Contributing](#contributing)
19+
- [Author](#author)
20+
- [License](#license)
21+
22+
## Usage
23+
24+
```swift
25+
import Concurrency
26+
27+
// Create `DispatchQueueFactory` instance
28+
let factory = DispatchQueueFactory()
29+
30+
// Build `main` queue from factory
31+
let mainQueue = factory.main()
32+
33+
// Build `global` queue with QOS
34+
let globalQueue = factory.global(qos: .background)
35+
36+
// Build `private` queue
37+
let privateQueue = factory.privateQueue(label: String(describing: self),
38+
qos: .background,
39+
attributes: .concurrent,
40+
autoreleaseFrequency: .inherit,
41+
target: nil)
42+
```
43+
44+
For testing purposes, you can use `TestConrurrency` target.
45+
46+
```swift
47+
import TestConcurrency
48+
49+
let testQueue = TestDispatchQueue()
50+
51+
// Run block immediately
52+
testQueue.async {}
53+
```
54+
55+
## Requirements
56+
- iOS 13.0+ / macOS 10.15+ / tvOS 11.0+ / watchOS 6.0+
57+
- Xcode 14.0
58+
- Swift 5
59+
60+
## Installation
61+
### Swift Package Manager
62+
63+
The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but `concurrency` does support its use on supported platforms.
64+
65+
Once you have your Swift package set up, adding `concurrency` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
66+
67+
```swift
68+
dependencies: [
69+
.package(url: "https://github.com/space-code/concurrency.git", .upToNextMajor(from: "0.0.1"))
70+
]
71+
```
72+
73+
## Communication
74+
- If you **found a bug**, open an issue.
75+
- If you **have a feature request**, open an issue.
76+
- If you **want to contribute**, submit a pull request.
77+
78+
## Contributing
79+
Bootstrapping development environment
80+
81+
```
82+
make bootstrap
83+
```
84+
85+
Please feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!
86+
87+
## Author
88+
Nikita Vasilev, nv3212@gmail.com
89+
90+
## License
91+
concurrency is available under the MIT license. See the LICENSE file for more info.

Resources/concurrency.png

308 KB
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// Concurrency
3+
// Copyright © 2023 Space Code. All rights reserved.
4+
//
5+
6+
import Foundation
7+
8+
extension DispatchQueue: IDispatchQueue {
9+
public func async(qos: DispatchQoS, flags: DispatchWorkItemFlags, execute work: @escaping @convention(block) () -> Void) {
10+
async(group: nil, qos: qos, flags: flags, execute: work)
11+
}
12+
}

0 commit comments

Comments
 (0)