diff --git a/Package.swift b/Package.swift index fda23f4..78076a1 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ import PackageDescription let package = Package( name: "Sio", platforms: [ - .macOS(.v10_11), .iOS(.v10), + .macOS(.v10_11), .iOS(.v10), .tvOS(.v10) ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. diff --git a/Sio.podspec b/Sio.podspec index 099880b..a7ef5bd 100644 --- a/Sio.podspec +++ b/Sio.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Sio" - s.version = "0.3.3" + s.version = "0.3.4" s.summary = "Swift IO" s.description = <<-DESC Swift Effects library, ala ZIO. diff --git a/Sources/Sio/Either.swift b/Sources/Sio/Either.swift index ac9a598..82b4c60 100644 --- a/Sources/Sio/Either.swift +++ b/Sources/Sio/Either.swift @@ -111,14 +111,14 @@ extension Either { } @inlinable - public static func mapLeft( + public static func mapLeft( _ transform: @escaping (A) -> C ) -> (Either) -> Either { { $0.mapLeft(transform) } } @inlinable - public static func mapRight( + public static func mapRight( _ transform: @escaping (B) -> C ) -> (Either) -> Either { { $0.mapRight(transform) } diff --git a/Sources/Sio/NoSyncValue.swift b/Sources/Sio/NoSyncValue.swift index 923faeb..dceb0dc 100644 --- a/Sources/Sio/NoSyncValue.swift +++ b/Sources/Sio/NoSyncValue.swift @@ -9,13 +9,13 @@ import Foundation public class NoSyncValue { - public enum State { + public enum State { case notLoaded case cancelled case loaded(Either) } - public var result: State = .notLoaded + public var result: State = .notLoaded public var notLoaded: Bool { switch self.result { diff --git a/Sources/Sio/SIO+Combine.swift b/Sources/Sio/SIO+Combine.swift index cf46978..14f8533 100644 --- a/Sources/Sio/SIO+Combine.swift +++ b/Sources/Sio/SIO+Combine.swift @@ -12,6 +12,7 @@ import Combine @available(iOS 13.0, *) @available(OSX 10.15, *) +@available(tvOS 13.0, *) extension SIO where R == Void, E: Error { public var future: AnyPublisher { Future { promise in diff --git a/Sources/Sio/SIO+Creation.swift b/Sources/Sio/SIO+Creation.swift index 7232e3b..973ebc2 100644 --- a/Sources/Sio/SIO+Creation.swift +++ b/Sources/Sio/SIO+Creation.swift @@ -35,7 +35,7 @@ public extension SIO { @inlinable static func fromFunc(_ f: @escaping (R) -> A) -> SIO { - environment().map(f) + SIO.environment().map(f) } } diff --git a/Sources/Sio/SIO+Requirements.swift b/Sources/Sio/SIO+Requirements.swift index 80cd9bb..e62cd47 100644 --- a/Sources/Sio/SIO+Requirements.swift +++ b/Sources/Sio/SIO+Requirements.swift @@ -73,20 +73,20 @@ public extension SIO { public extension SIO { @inlinable - static func environment() -> SIO { + static func environment() -> SIO { access(id) } @inlinable - static func access(_ f: @escaping (R) -> S) -> SIO { + static func access(_ f: @escaping (R) -> S) -> SIO { SIO.sync({ r in .right(f(r)) }) } @inlinable - static func accessM(_ f: @escaping (R) -> SIO) -> SIO { - environment().flatMap(f) + static func accessM(_ f: @escaping (R) -> SIO) -> SIO { + self.environment().flatMap(f) } } diff --git a/Sources/Sio/SIO.swift b/Sources/Sio/SIO.swift index 737a1a7..ad0ffe0 100644 --- a/Sources/Sio/SIO.swift +++ b/Sources/Sio/SIO.swift @@ -31,10 +31,10 @@ public final class SIO { var bfm: BiFlatMapBase? { switch self { - case let .biFlatMap(bfm): - return bfm - default: - return nil + case let .biFlatMap(bfm): + return bfm + default: + return nil } } } @@ -44,7 +44,7 @@ public final class SIO { @usableFromInline var _running = false - + private let runningSyncQueue = DispatchQueue(label: "sio_running", attributes: .concurrent) public var running: Bool { get { @@ -134,58 +134,58 @@ public final class SIO { self.running = true switch self.implementation { - case let .success(a): - resolve(a) - self.running = false - case let .fail(e): - reject(e) - self.running = false - case let .sync(sync): - defer { self.running = false } - - let res = sync(requirement) - guard self.cancelled == false else { - return - } - - switch res { - case let .left(e)?: - reject(e) - case let .right(a)?: + case let .success(a): resolve(a) - case nil: - return - } - case let .async(async): - async( - requirement, - { error in - self.running = false - guard !self.cancelled else { return } - reject(error) - }, - { result in - self.running = false - guard !self.cancelled else { return } - resolve(result) - } - ) - case let .biFlatMap(impl): - impl.fork(requirement, { e in - guard self.cancelled == false else { - return - } - + self.running = false + case let .fail(e): reject(e) self.running = false - }, { a in + case let .sync(sync): + defer { self.running = false } + + let res = sync(requirement) guard self.cancelled == false else { return } - resolve(a) - self.running = false - }) + switch res { + case let .left(e)?: + reject(e) + case let .right(a)?: + resolve(a) + case nil: + return + } + case let .async(async): + async( + requirement, + { error in + self.running = false + guard !self.cancelled else { return } + reject(error) + }, + { result in + self.running = false + guard !self.cancelled else { return } + resolve(result) + } + ) + case let .biFlatMap(impl): + impl.fork(requirement, { e in + guard self.cancelled == false else { + return + } + + reject(e) + self.running = false + }, { a in + guard self.cancelled == false else { + return + } + + resolve(a) + self.running = false + }) } } @@ -275,10 +275,10 @@ final class BiFlatMap: BiFlatMapBase { sio: self.sio, err: { e0 in self.err(e0).bimap(f, g) - }, + }, succ: { a0 in self.succ(a0).bimap(f, g) - } + } ) return SIO.init( @@ -296,10 +296,10 @@ final class BiFlatMap: BiFlatMapBase { sio: self.sio, err: { e0 in self.err(e0).biFlatMap(f, g) - }, + }, succ: { a0 in self.succ(a0).biFlatMap(f, g) - } + } ) return SIO.init( diff --git a/Sources/Sio/SyncValue.swift b/Sources/Sio/SyncValue.swift index 7d79a85..cbf4451 100644 --- a/Sources/Sio/SyncValue.swift +++ b/Sources/Sio/SyncValue.swift @@ -9,16 +9,16 @@ import Foundation public class SyncValue { - public enum State { + public enum State { case notLoaded case cancelled case loaded(Either) } private let barrier = DispatchQueue(label: "es.josesanchez.barrier", attributes: .concurrent) - private var _result: State = .notLoaded + private var _result: State = .notLoaded - public var result: State { + public var result: State { set { barrier.async(flags: .barrier) { self._result = newValue @@ -26,7 +26,7 @@ public class SyncValue { } get { - var res: State? + var res: State? barrier.sync { res = self._result } diff --git a/Tests/SioEffectsTests/CancellationTests.swift b/Tests/SioEffectsTests/CancellationTests.swift index d616b46..e5cddf4 100644 --- a/Tests/SioEffectsTests/CancellationTests.swift +++ b/Tests/SioEffectsTests/CancellationTests.swift @@ -193,7 +193,6 @@ class CancellationTests: XCTestCase { task .fork( { _ in - XCTFail() }, { a in XCTFail() diff --git a/Tests/sioTests/MonadTests.swift b/Tests/sioTests/MonadTests.swift index 95ab88a..d2c774c 100644 --- a/Tests/sioTests/MonadTests.swift +++ b/Tests/sioTests/MonadTests.swift @@ -73,7 +73,6 @@ class MonadTests: XCTestCase { IO.rejected("blah") .default(1) .fork({ _ in - XCTFail() }) { value in XCTAssert(value == 1) expectation.fulfill()