Skip to content

Commit

Permalink
Merge pull request #41 from orchetect/concurrency-refactor
Browse files Browse the repository at this point in the history
Concurrency Refactor
  • Loading branch information
orchetect authored Jan 23, 2025
2 parents f55f2cc + f8bb282 commit 9b838f0
Show file tree
Hide file tree
Showing 159 changed files with 1,595 additions and 918 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ jobs:
with:
xcode-version: latest-stable
- name: Build
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=macOS,name=Any Mac" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=macOS,name=Any Mac" | xcbeautify && exit ${PIPESTATUS[0]}
- name: Unit Tests
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=macOS" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=macOS" | xcbeautify && exit ${PIPESTATUS[0]}

macOS-swift6:
name: macOS (Swift 6.0)
Expand All @@ -50,9 +50,9 @@ jobs:
- name: Set Package to Swift 6.0
run: swift package tools-version --set "6.0"
- name: Build
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=macOS,name=Any Mac" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=macOS,name=Any Mac" | xcbeautify && exit ${PIPESTATUS[0]}
- name: Unit Tests
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=macOS" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=macOS" | xcbeautify && exit ${PIPESTATUS[0]}

macCatalyst:
name: macCatalyst
Expand All @@ -63,9 +63,9 @@ jobs:
with:
xcode-version: latest-stable
- name: Build
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=macOS,variant=Mac Catalyst,name=Any Mac" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=macOS,variant=Mac Catalyst,name=Any Mac" | xcbeautify && exit ${PIPESTATUS[0]}
- name: Unit Tests
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=macOS,variant=Mac Catalyst" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=macOS,variant=Mac Catalyst" | xcbeautify && exit ${PIPESTATUS[0]}

iOS:
name: iOS
Expand All @@ -76,15 +76,15 @@ jobs:
with:
xcode-version: latest-stable
- name: Build
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=iOS Simulator,name=Any iOS Device" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=iOS Simulator,name=Any iOS Device" | xcbeautify && exit ${PIPESTATUS[0]}
- name: Prepare Destination Device Name
shell: bash
run: |
DESTNAME=$(xcodebuild -showdestinations -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" | perl -nle 'if (m/iOS\sSimulator.*(iPhone\s[\d]{2}.*)\s\}\.*/g) { print $1; }' | sort -r | head -n 1)
echo Using device \"$DESTNAME\"
echo "DESTNAME=$DESTNAME" >> "$GITHUB_ENV"
- name: Unit Tests
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=iOS Simulator,name=$DESTNAME" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=iOS Simulator,name=$DESTNAME" | xcbeautify && exit ${PIPESTATUS[0]}

tvOS:
name: tvOS
Expand All @@ -95,15 +95,15 @@ jobs:
with:
xcode-version: latest-stable
- name: Build
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=tvOS Simulator,name=Any tvOS Simulator Device" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=tvOS Simulator,name=Any tvOS Simulator Device" | xcbeautify && exit ${PIPESTATUS[0]}
- name: Prepare Destination Device Name
shell: bash
run: |
DESTNAME=$(xcodebuild -showdestinations -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" | perl -nle 'if (m/tvOS\sSimulator.*(Apple\sTV\s4K.*)\s\}\.*/g) { print $1; }' | sort -r | head -n 1)
echo Using device \"$DESTNAME\"
echo "DESTNAME=$DESTNAME" >> "$GITHUB_ENV"
- name: Unit Tests
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=tvOS Simulator,name=$DESTNAME" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=tvOS Simulator,name=$DESTNAME" | xcbeautify && exit ${PIPESTATUS[0]}

watchOS:
name: watchOS
Expand All @@ -114,15 +114,15 @@ jobs:
with:
xcode-version: latest-stable
- name: Build
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=watchOS Simulator,name=Any watchOS Simulator Device" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "generic/platform=watchOS Simulator,name=Any watchOS Simulator Device" | xcbeautify && exit ${PIPESTATUS[0]}
- name: Prepare Destination Device Name
shell: bash
run: |
DESTNAME=$(xcodebuild -showdestinations -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" | perl -nle 'if (m/watchOS\sSimulator.*(Apple\sWatch\sSeries\s[\d]{2}.*)\s\}\.*/g) { print $1; }' | sort -r | head -n 1)
echo Using device \"$DESTNAME\"
echo "DESTNAME=$DESTNAME" >> "$GITHUB_ENV"
- name: Unit Tests
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=watchOS Simulator,name=$DESTNAME" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "$SCHEME" -destination "platform=watchOS Simulator,name=$DESTNAME" | xcbeautify && exit ${PIPESTATUS[0]}

examples:
name: Examples
Expand All @@ -134,26 +134,26 @@ jobs:
xcode-version: latest-stable

- name: Basic Example - Resolve Package Dependencies # needed because sometimes xcodebuild fails otherwise
run: xcodebuild -project "Examples/Basic Example/Basic Example.xcodeproj" -resolvePackageDependencies | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild -project "Examples/Basic Example/Basic Example.xcodeproj" -resolvePackageDependencies | xcbeautify && exit ${PIPESTATUS[0]}
- name: Basic Example - Build
run: xcodebuild build -project "Examples/Basic Example/Basic Example.xcodeproj" -scheme "Basic Example" -destination "generic/platform=macOS,name=Any Mac" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -project "Examples/Basic Example/Basic Example.xcodeproj" -scheme "Basic Example" -destination "generic/platform=macOS,name=Any Mac" | xcbeautify && exit ${PIPESTATUS[0]}

- name: Custom Type Example - Resolve Package Dependencies # needed because sometimes xcodebuild fails otherwise
run: xcodebuild -project "Examples/Custom Type Example/Custom Type Example.xcodeproj" -resolvePackageDependencies | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild -project "Examples/Custom Type Example/Custom Type Example.xcodeproj" -resolvePackageDependencies | xcbeautify && exit ${PIPESTATUS[0]}
- name: Custom Type Example - Build
run: xcodebuild build -project "Examples/Custom Type Example/Custom Type Example.xcodeproj" -scheme "Custom Type Example" -destination "generic/platform=macOS,name=Any Mac" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -project "Examples/Custom Type Example/Custom Type Example.xcodeproj" -scheme "Custom Type Example" -destination "generic/platform=macOS,name=Any Mac" | xcbeautify && exit ${PIPESTATUS[0]}

- name: Method Blocks Example - Resolve Package Dependencies # needed because sometimes xcodebuild fails otherwise
run: xcodebuild -project "Examples/Method Blocks Example/Method Blocks Example.xcodeproj" -resolvePackageDependencies | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild -project "Examples/Method Blocks Example/Method Blocks Example.xcodeproj" -resolvePackageDependencies | xcbeautify && exit ${PIPESTATUS[0]}
- name: Method Blocks Example - Build
run: xcodebuild build -project "Examples/Method Blocks Example/Method Blocks Example.xcodeproj" -scheme "Method Blocks Example" -destination "generic/platform=macOS,name=Any Mac" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -project "Examples/Method Blocks Example/Method Blocks Example.xcodeproj" -scheme "Method Blocks Example" -destination "generic/platform=macOS,name=Any Mac" | xcbeautify && exit ${PIPESTATUS[0]}

- name: Method IDs Example - Resolve Package Dependencies # needed because sometimes xcodebuild fails otherwise
run: xcodebuild -project "Examples/Method IDs Example/Method IDs Example.xcodeproj" -resolvePackageDependencies | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild -project "Examples/Method IDs Example/Method IDs Example.xcodeproj" -resolvePackageDependencies | xcbeautify && exit ${PIPESTATUS[0]}
- name: Method IDs Example - Build
run: xcodebuild build -project "Examples/Method IDs Example/Method IDs Example.xcodeproj" -scheme "Method IDs Example" -destination "generic/platform=macOS,name=Any Mac" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -project "Examples/Method IDs Example/Method IDs Example.xcodeproj" -scheme "Method IDs Example" -destination "generic/platform=macOS,name=Any Mac" | xcbeautify && exit ${PIPESTATUS[0]}

- name: Socket Example - Resolve Package Dependencies # needed because sometimes xcodebuild fails otherwise
run: xcodebuild -project "Examples/Socket Example/Socket Example.xcodeproj" -resolvePackageDependencies | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild -project "Examples/Socket Example/Socket Example.xcodeproj" -resolvePackageDependencies | xcbeautify && exit ${PIPESTATUS[0]}
- name: Socket Example - Build
run: xcodebuild build -project "Examples/Socket Example/Socket Example.xcodeproj" -scheme "Socket Example" -destination "generic/platform=macOS,name=Any Mac" | xcpretty && exit ${PIPESTATUS[0]}
run: xcodebuild build -project "Examples/Socket Example/Socket Example.xcodeproj" -scheme "Socket Example" -destination "generic/platform=macOS,name=Any Mac" | xcbeautify && exit ${PIPESTATUS[0]}
4 changes: 2 additions & 2 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
--groupedextension "MARK: %c"
--guardelse auto
--header "\n {file}\n OSCKit • https://github.com/orchetect/OSCKit\n © 2020-{year} Steffan Andrews • Licensed under MIT License\n"
--hexgrouping 4,8
--hexgrouping 8,8
--hexliteralcase uppercase
--ifdef no-indent
--importgrouping alpha
Expand All @@ -37,7 +37,7 @@
--markcategories true
--markextensions always
--marktypes always
--maxwidth 120
--maxwidth 140
--modifierorder
--nevertrailing
--nospaceoperators
Expand Down
1 change: 1 addition & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/OSCKit-CI.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableThreadSanitizer = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion Examples/Basic Example/Basic Example/BasicExampleApp.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// BasicExampleApp.swift
// OSCKit • https://github.com/orchetect/OSCKit
// © 2020-2024 Steffan Andrews • Licensed under MIT License
// © 2020-2025 Steffan Andrews • Licensed under MIT License
//

import SwiftUI
Expand Down
4 changes: 2 additions & 2 deletions Examples/Basic Example/Basic Example/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//
// ContentView.swift
// OSCKit • https://github.com/orchetect/OSCKit
// © 2020-2024 Steffan Andrews • Licensed under MIT License
// © 2020-2025 Steffan Andrews • Licensed under MIT License
//

import SwiftUI
import OSCKit
import SwiftUI

struct ContentView: View {
@EnvironmentObject private var oscManager: OSCManager
Expand Down
19 changes: 9 additions & 10 deletions Examples/Basic Example/Basic Example/OSCManager.swift
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
//
// OSCManager.swift
// OSCKit • https://github.com/orchetect/OSCKit
// © 2020-2024 Steffan Andrews • Licensed under MIT License
// © 2020-2025 Steffan Andrews • Licensed under MIT License
//

import Foundation
import OSCKit

/// OSC lifecycle and send/receive manager.
@MainActor
final class OSCManager: ObservableObject {
final class OSCManager: ObservableObject, Sendable {
private let client = OSCClient()
private let server = OSCServer(port: 8000)

init() {
Task { await start() }
start()
}
}

// MARK: - Lifecycle

extension OSCManager {
/// Call this once on app launch.
func start() async {
func start() {
// setup client
do { try client.start() } catch { print(error) }

// setup server
await server.setHandler { [weak self] message, timeTag in
await self?.handle(message: message, timeTag: timeTag)
server.setHandler { [weak self] message, timeTag in
self?.handle(message: message, timeTag: timeTag)
}
do { try await server.start() } catch { print(error) }
do { try server.start() } catch { print(error) }
}

func stop() async {
func stop() {
client.stop()
await server.stop()
server.stop()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//
// ContentView.swift
// OSCKit • https://github.com/orchetect/OSCKit
// © 2020-2024 Steffan Andrews • Licensed under MIT License
// © 2020-2025 Steffan Andrews • Licensed under MIT License
//

import SwiftUI
import OSCKit
import SwiftUI

struct ContentView: View {
@EnvironmentObject private var oscManager: OSCManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// CustomType.swift
// OSCKit • https://github.com/orchetect/OSCKit
// © 2020-2024 Steffan Andrews • Licensed under MIT License
// © 2020-2025 Steffan Andrews • Licensed under MIT License
//

import Foundation
Expand All @@ -16,7 +16,7 @@ import OSCKitCore
// to use the OSC Type "string" as the underlying data storage within an OSC message. There are no particular benefits
// or drawbacks of either choice, and is strictly implementation semantics.

struct CustomType: Equatable, Hashable, Codable {
struct CustomType: Equatable, Hashable, Codable, Sendable {
let id: Int
let name: String
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// CustomTypeExampleApp.swift
// OSCKit • https://github.com/orchetect/OSCKit
// © 2020-2024 Steffan Andrews • Licensed under MIT License
// © 2020-2025 Steffan Andrews • Licensed under MIT License
//

import SwiftUI
Expand Down
31 changes: 14 additions & 17 deletions Examples/Custom Type Example/Custom Type Example/OSCManager.swift
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
//
// OSCManager.swift
// OSCKit • https://github.com/orchetect/OSCKit
// © 2020-2024 Steffan Andrews • Licensed under MIT License
// © 2020-2025 Steffan Andrews • Licensed under MIT License
//

import Foundation
import OSCKit

/// OSC lifecycle and send/receive manager.
@MainActor
final class OSCManager: ObservableObject {
final class OSCManager: ObservableObject, Sendable {
private let client = OSCClient()
private let server = OSCServer(port: 8000)

init() {
Task {
do {
try await OSCSerialization.shared.registerType(CustomType.self)
} catch {
print(error.localizedDescription)
}

await start()
do {
try OSCSerialization.shared.registerType(CustomType.self)
} catch {
print(error.localizedDescription)
}

start()
}
}

// MARK: - Lifecycle

extension OSCManager {
/// Call this once on app launch.
func start() async {
func start() {
// setup client
do { try client.start() } catch { print(error) }

// setup server
await server.setHandler { [weak self] message, timeTag in
await self?.handle(message: message, timeTag: timeTag)
server.setHandler { [weak self] message, timeTag in
self?.handle(message: message, timeTag: timeTag)
}
do { try await server.start() } catch { print(error) }
do { try server.start() } catch { print(error) }
}

func stop() async {
func stop() {
client.stop()
await server.stop()
server.stop()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//
// ContentView.swift
// OSCKit • https://github.com/orchetect/OSCKit
// © 2020-2024 Steffan Andrews • Licensed under MIT License
// © 2020-2025 Steffan Andrews • Licensed under MIT License
//

import SwiftUI
import OSCKit
import SwiftUI

struct ContentView: View {
@EnvironmentObject private var oscManager: OSCManager
Expand Down Expand Up @@ -63,6 +63,7 @@ struct ContentView: View {

oscManager.send(oscMessage, to: "localhost", port: 8000)
}

private func sendTestOSCMessageCWithNoOptionalValue() {
let oscMessage = OSCMessage(
"/some/address/methodC",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// MethodBlocksExampleApp.swift
// OSCKit • https://github.com/orchetect/OSCKit
// © 2020-2024 Steffan Andrews • Licensed under MIT License
// © 2020-2025 Steffan Andrews • Licensed under MIT License
//

import SwiftUI
Expand Down
Loading

0 comments on commit 9b838f0

Please sign in to comment.