Skip to content

Commit

Permalink
Correct spelling.
Browse files Browse the repository at this point in the history
  • Loading branch information
BB9z committed Dec 12, 2022
1 parent a53147c commit b2cd9b9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/b9swift/Action.git",
"state": {
"branch": null,
"revision": "ad6665b193e5f79658e2bca2a013e99ed6c3dd56",
"version": "1.0.0"
"revision": "32ccacba992b921e304438ca6d6cfa20fef6e840",
"version": "1.1.0"
}
}
]
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
[![Swift Package Manager](https://img.shields.io/badge/spm-compatible-F05138.svg?style=flat-square)](https://swift.org/package-manager)
[![Build Status](https://img.shields.io/github/workflow/status/b9swift/Condition/Swift?style=flat-square&colorA=555555&colorB=F05138)](https://github.com/b9swift/Condition/actions)
[![gitee 镜像](https://img.shields.io/badge/%E9%95%9C%E5%83%8F-gitee-C61E22.svg?style=flat-square)](https://gitee.com/b9swift/Condition)
[![GitHub Source](https://img.shields.io/badge/Source-GitHub-24292F.svg?style=flat-square)](https://github.com/b9swift/Condition)

Maintains a set of states that allows it to perform observation actions when the specific states are satisfied.

## Installation

Using Swift Package Manager or import manually.
You can use either Swift Package Manager or manual importing to add this package or module to your project.

你也可以使用 [gitee 镜像](https://gitee.com/b9swift/Condition)
12 changes: 6 additions & 6 deletions Sources/B9Condition/B9Condition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Foundation

It always has a delay between status changing and observer triggering.

Instance must be hold with strong refrence, or it will be released and all observe will be canceled immediately. With one exception:
Instance must be hold with strong reference, or it will be released and all observe will be canceled immediately. With one exception:

- If there are actions being executed in other threads, this instance will be temporarily held.

Expand All @@ -35,7 +35,7 @@ public final class Condition<T: SetAlgebra> {
self.queue = queue
}

/// The defualt queue. Observer action is perfromed in this queue if not specified.
/// The default queue. Observer action is performed in this queue if not specified.
public let queue: DispatchQueue

/// Returns whether current states meets the given flags.
Expand Down Expand Up @@ -162,13 +162,13 @@ public final class Condition<T: SetAlgebra> {

internal var debugDescription: String {
let properties: [(String, Any?)] = [("flags", flags), ("queue", queue), ("shouldAutoRemove", shouldAutoRemove), ("action", action)]
let propertyDiscription = properties.compactMap { key, value in
let propertyDescription = properties.compactMap { key, value in
if let value = value {
return "\(key) = \(value)"
}
return nil
}.joined(separator: ", ")
return "<Observer \(Unmanaged.passUnretained(self).toOpaque()): \(propertyDiscription)>"
return "<Observer \(Unmanaged.passUnretained(self).toOpaque()): \(propertyDescription)>"
}
}

Expand Down Expand Up @@ -197,12 +197,12 @@ public final class Condition<T: SetAlgebra> {
extension Condition: CustomDebugStringConvertible {
public var debugDescription: String {
let properties: [(String, Any?)] = [("flags", flags), ("queue", queue), ("observers", observers)]
let propertyDiscription = properties.compactMap { key, value in
let propertyDescription = properties.compactMap { key, value in
if let value = value {
return "\(key) = \(value)"
}
return nil
}.joined(separator: ", ")
return "<Condition \(Unmanaged.passUnretained(self).toOpaque()): \(propertyDiscription)>"
return "<Condition \(Unmanaged.passUnretained(self).toOpaque()): \(propertyDescription)>"
}
}
24 changes: 12 additions & 12 deletions Tests/B9ConditionTests/B9ConditionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class B9ConditionTests: XCTestCase {
} else if counter == 2 {
print("observer 2nd")
} else {
fatalError("Should not hanppen")
fatalError("Should not happen")
}
}, queue: observerQueue, autoRemove: false)
after(0.1) {
Expand Down Expand Up @@ -122,7 +122,7 @@ final class B9ConditionTests: XCTestCase {
XCTAssertEqual(condition.observers.count, 0)
}

func testWaitTimout() {
func testWaitTimeout() {
let condition = Condition<OptionFlag>()
condition.wait(.a, action: Action {
fatalError("Never")
Expand Down Expand Up @@ -163,7 +163,7 @@ final class B9ConditionTests: XCTestCase {
after(0.1) {
XCTAssertTrue(isCalled, "Should called after reset")

XCTAssertNotNil(observer, "Observer is keeped by condition")
XCTAssertNotNil(observer, "Observer is retained by condition")
condition.remove(observer: observer)
XCTAssertNil(observer, "After remove, observer should autoreleased")

Expand Down Expand Up @@ -216,12 +216,12 @@ final class B9ConditionTests: XCTestCase {
}

func testReleaseWithoutTimeout() {
strongRefrence = Condition<OptionFlag>()
strongRefrence.wait(.a, action: Action({
strongReference = Condition<OptionFlag>()
strongReference.wait(.a, action: Action({
fatalError("Should not executed")
}, reference: nil), timeout: 0)
strongRefrence.set(on: [.a])
strongRefrence = nil
strongReference.set(on: [.a])
strongReference = nil
let testEnd = XCTestExpectation()
after(0.1) {
testEnd.fulfill()
Expand All @@ -230,13 +230,13 @@ final class B9ConditionTests: XCTestCase {
}

func testReleaseWithTimeout() {
strongRefrence = Condition<OptionFlag>()
strongRefrence.wait(.a, action: Action({
strongReference = Condition<OptionFlag>()
strongReference.wait(.a, action: Action({
fatalError("Should not executed")
}, reference: nil), timeout: 1)
after(0.1) {
self.strongRefrence.set(on: [.a])
self.strongRefrence = nil
self.strongReference.set(on: [.a])
self.strongReference = nil
}
let testEnd = XCTestExpectation()
after(0.2) {
Expand All @@ -245,7 +245,7 @@ final class B9ConditionTests: XCTestCase {
wait(for: [testEnd], timeout: 2)
}

var strongRefrence: Condition<OptionFlag>!
var strongReference: Condition<OptionFlag>!

private func after(_ second: TimeInterval, do work: @escaping () -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + second, execute: work)
Expand Down

0 comments on commit b2cd9b9

Please sign in to comment.