Skip to content

Commit

Permalink
Sendable conformances.
Browse files Browse the repository at this point in the history
  • Loading branch information
buscarini committed Oct 31, 2024
1 parent 681789c commit a3bc281
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version:5.3
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Sio",
platforms: [
.macOS(.v10_11), .iOS(.v10), .tvOS(.v10)
.macOS(.v10_11), .iOS(.v13), .tvOS(.v13)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand Down
2 changes: 2 additions & 0 deletions Sources/Sio/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation

@Sendable
public func |> <A, B>(_ a: A, _ f: (A) throws -> B) rethrows -> B {
return try f(a)
}
Expand All @@ -17,6 +18,7 @@ public func |> <A, B>(_ a: A, _ f: (A) throws -> B) rethrows -> B {
/// - a: A mutable value.
/// - f: An in-out function.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
@Sendable
public func |> <A>(_ a: inout A, _ f: (inout A) throws -> Void) rethrows {
try f(&a)
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/Sio/Either.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,5 @@ extension Either where A == B {
bimap(f, f)
}
}

extension Either: Sendable where A: Sendable, B: Sendable {}
4 changes: 4 additions & 0 deletions Sources/Sio/Prelude.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
import Foundation

@inlinable
@Sendable
public func id<a>(_ a: a) -> a {
a
}

@inlinable
@Sendable
public func absurd<A>(_ n: Never) -> A {}

@inlinable
@Sendable
public func discard<A, B>(_ f: @escaping (A) -> B) -> (A) -> Void {
{ a in
_ = f(a)
}
}

@inlinable
@Sendable
public func const<A, B>(_ b: B) -> (_ a: A) -> B {
{ _ in b }
}
15 changes: 15 additions & 0 deletions Sources/Sio/SIO+Async.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

extension SIO where R == Void, E: Error {
public var await: A {
get async throws {
try await withCheckedThrowingContinuation { continuation in
self.fork { error in
continuation.resume(throwing: error)
} _: { value in
continuation.resume(returning: value)
}
}
}
}
}
2 changes: 1 addition & 1 deletion Sources/Sio/Seconds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Seconds<T: Numeric>: RawRepresentable {
public struct Seconds<T: Numeric & Sendable>: RawRepresentable, Sendable {
public var rawValue: T

public init(rawValue: T) {
Expand Down

0 comments on commit a3bc281

Please sign in to comment.