Skip to content

Commit

Permalink
fix: Fixes for tvOS. Fixes for Swift 6.
Browse files Browse the repository at this point in the history
  • Loading branch information
buscarini committed Jan 15, 2024
1 parent 133907a commit 42e3303
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 70 deletions.
4 changes: 2 additions & 2 deletions Sources/Sio/Either.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ extension Either {
}

@inlinable
public static func mapLeft<A, B, C>(
public static func mapLeft<C>(
_ transform: @escaping (A) -> C
) -> (Either<A, B>) -> Either<C, B> {
{ $0.mapLeft(transform) }
}

@inlinable
public static func mapRight<A, B, C>(
public static func mapRight<C>(
_ transform: @escaping (B) -> C
) -> (Either<A, B>) -> Either<A, C> {
{ $0.mapRight(transform) }
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sio/NoSyncValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import Foundation

public class NoSyncValue<E, A> {
public enum State<E, A> {
public enum State {
case notLoaded
case cancelled
case loaded(Either<E, A>)
}

public var result: State<E, A> = .notLoaded
public var result: State = .notLoaded

public var notLoaded: Bool {
switch self.result {
Expand Down
1 change: 1 addition & 0 deletions Sources/Sio/SIO+Combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<A, E> {
Future<A, E> { promise in
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sio/SIO+Creation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public extension SIO {

@inlinable
static func fromFunc(_ f: @escaping (R) -> A) -> SIO<R, Never, A> {
environment().map(f)
SIO<R, Never, A>.environment().map(f)
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Sio/SIO+Requirements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ public extension SIO {

public extension SIO {
@inlinable
static func environment<R, E>() -> SIO<R, E, R> {
static func environment() -> SIO<R, E, R> {
access(id)
}

@inlinable
static func access<S, R, E>(_ f: @escaping (R) -> S) -> SIO<R, E, S> {
static func access<S>(_ f: @escaping (R) -> S) -> SIO<R, E, S> {
SIO<R, E, S>.sync({ r in
.right(f(r))
})
}

@inlinable
static func accessM<R, E>(_ f: @escaping (R) -> SIO<R, E, A>) -> SIO<R, E, A> {
environment().flatMap(f)
static func accessM(_ f: @escaping (R) -> SIO<R, E, A>) -> SIO<R, E, A> {
self.environment().flatMap(f)
}
}

Expand Down
108 changes: 54 additions & 54 deletions Sources/Sio/SIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public final class SIO<R, E, A> {

var bfm: BiFlatMapBase<R, E, A>? {
switch self {
case let .biFlatMap(bfm):
return bfm
default:
return nil
case let .biFlatMap(bfm):
return bfm
default:
return nil
}
}
}
Expand All @@ -44,7 +44,7 @@ public final class SIO<R, E, A> {

@usableFromInline
var _running = false

private let runningSyncQueue = DispatchQueue(label: "sio_running", attributes: .concurrent)
public var running: Bool {
get {
Expand Down Expand Up @@ -134,58 +134,58 @@ public final class SIO<R, E, A> {
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
})
}
}

Expand Down Expand Up @@ -275,10 +275,10 @@ final class BiFlatMap<R, E0, E, A0, A>: BiFlatMapBase<R, E, A> {
sio: self.sio,
err: { e0 in
self.err(e0).bimap(f, g)
},
},
succ: { a0 in
self.succ(a0).bimap(f, g)
}
}
)

return SIO<R, F, B>.init(
Expand All @@ -296,10 +296,10 @@ final class BiFlatMap<R, E0, E, A0, A>: BiFlatMapBase<R, E, A> {
sio: self.sio,
err: { e0 in
self.err(e0).biFlatMap(f, g)
},
},
succ: { a0 in
self.succ(a0).biFlatMap(f, g)
}
}
)

return SIO<R, F, B>.init(
Expand Down
8 changes: 4 additions & 4 deletions Sources/Sio/SyncValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
import Foundation

public class SyncValue<E, A> {
public enum State<E, A> {
public enum State {
case notLoaded
case cancelled
case loaded(Either<E, A>)
}

private let barrier = DispatchQueue(label: "es.josesanchez.barrier", attributes: .concurrent)
private var _result: State<E, A> = .notLoaded
private var _result: State = .notLoaded

public var result: State<E, A> {
public var result: State {
set {
barrier.async(flags: .barrier) {
self._result = newValue
}
}

get {
var res: State<E, A>?
var res: State?
barrier.sync {
res = self._result
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/SioEffectsTests/CancellationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CancellationTests: XCTestCase {
let scheduler = TestScheduler()

func testNoCancellation() {
var lastValue: Int = 0
let lastValue: Int = 0
var task: UIO<Void>?

let finish = expectation(description: "finish")
Expand Down Expand Up @@ -193,7 +193,6 @@ class CancellationTests: XCTestCase {
task
.fork(
{ _ in
XCTFail()
},
{ a in
XCTFail()
Expand Down
1 change: 0 additions & 1 deletion Tests/sioTests/MonadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class MonadTests: XCTestCase {
IO<String, Int>.rejected("blah")
.default(1)
.fork({ _ in
XCTFail()
}) { value in
XCTAssert(value == 1)
expectation.fulfill()
Expand Down

0 comments on commit 42e3303

Please sign in to comment.