Skip to content

Commit

Permalink
Swift6 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored Oct 11, 2024
1 parent 3ddc450 commit 4f9a344
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 326 deletions.
34 changes: 6 additions & 28 deletions .github/workflows/Checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,27 @@ on:
branches: "*"

jobs:
pod-lint:
runs-on: macos-12

steps:
- uses: maxim-lobanov/setup-xcode@v1.1
with:
xcode-version: "13.3"
- uses: actions/checkout@v2
- name: Run lint
run: pod lib lint --allow-warnings

build-xcodebuild:
runs-on: macos-12
runs-on: macos-14

steps:
- uses: maxim-lobanov/setup-xcode@v1.1
with:
xcode-version: "13.3"
xcode-version: "16.0"
- uses: actions/checkout@v2
- name: xcodebuild
run: xcodebuild -scheme BulkLogger -sdk iphoneos -destination 'generic/platform=iOS'

build-swiftpm:
runs-on: macos-12

steps:
- uses: maxim-lobanov/setup-xcode@v1.1
with:
xcode-version: "13.3"
- uses: actions/checkout@v2
- name: SwiftPM
run: swift build
run: set -o pipefail && xcodebuild -scheme Bulk-Package -sdk iphoneos -destination 'generic/platform=iOS' | xcbeautify

test:
runs-on: macos-12
runs-on: macos-14

steps:
- uses: maxim-lobanov/setup-xcode@v1.1
with:
xcode-version: "13.3"
xcode-version: "16.0"
- uses: actions/checkout@v2
with:
submodules: true
- name: Run
run: |
swift test
set -o pipefail && xcodebuild -scheme Bulk-Package -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16 Pro' test | xcbeautify
26 changes: 0 additions & 26 deletions Bulk.podspec

This file was deleted.

11 changes: 5 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
// swift-tools-version:5.6
// swift-tools-version:6.0
import PackageDescription

let package = Package(
name: "Bulk",
name: "Bulk",
platforms: [
.macOS(.v11),
.iOS(.v13),
.iOS(.v16),
.tvOS(.v13),
.watchOS(.v5)
.watchOS(.v6),
],
products: [
.library(name: "Bulk", targets: ["Bulk"]),
.library(name: "BulkLogger", targets: ["BulkLogger"]),
],
dependencies: [
],
dependencies: [],
targets: [
.target(name: "Bulk", dependencies: []),
.target(name: "BulkLogger", dependencies: ["Bulk"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@

import Foundation

public final class BulkSinkGroup<Element>: BulkSinkType {

private let sinks: AnyCollection<AnyBulkSink<Element>>

public init<Sink: BulkSinkType>(_ sink: Sink) where Sink.Element == Element {
self.sinks = AnyCollection(CollectionOfOne<AnyBulkSink<Element>>.init(.init(sink)))
}
public enum BufferResult<Element> {
case stored
case flowed([Element])
}

public protocol Buffer {

associatedtype Element

public init<C: Collection>(_ sinks: C) where C.Element == AnyBulkSink<Element> {
self.sinks = AnyCollection(sinks)
}
var hasSpace: Bool { get }

public func send(_ element: Element) {
sinks.forEach {
$0.send(element)
}
}
/// Buffer item
///
/// - Parameter string:
/// - Returns:
func write(element: Element) -> BufferResult<Element>

/// Purge buffered items
///
/// - Returns: purged items
func purge() -> [Element]
}
8 changes: 5 additions & 3 deletions Sources/Bulk/Buffers/FileBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@

import Foundation

public final class FileBuffer<Element, Serializer: SerializerType>: BufferType where Serializer.Element == Element {
public final class FileBuffer<Element, Serializer: SerializerType>: Buffer where Serializer.Element == Element {

public var hasSpace: Bool {
return lineCount() < size
}

private let fileManager = FileManager.default
nonisolated(unsafe) private let fileManager = FileManager.default
public let fileURL: URL

nonisolated(unsafe)
private var fileHandle: FileHandle?
public let size: Int

Expand Down
2 changes: 1 addition & 1 deletion Sources/Bulk/Buffers/MemoryBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import Foundation

public final class MemoryBuffer<Element>: BufferType {
public final class MemoryBuffer<Element>: Buffer {

public var hasSpace: Bool {
return cursor < size
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bulk/Buffers/PassthroughBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import Foundation

public struct PassthroughBuffer<Element>: BufferType {
public struct PassthroughBuffer<Element>: Buffer {

public var hasSpace: Bool {
return false
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bulk/Buffers/SerializerType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import Foundation

public protocol SerializerType {
public protocol SerializerType: Sendable {

associatedtype Element

Expand Down
81 changes: 0 additions & 81 deletions Sources/Bulk/Core/Buffer.swift

This file was deleted.

46 changes: 14 additions & 32 deletions Sources/Bulk/Core/BulkBufferTimer.swift
Original file line number Diff line number Diff line change
@@ -1,60 +1,42 @@
import Foundation

public struct BulkBufferTimer {
public final class BulkBufferTimer {

private let interval: DispatchTimeInterval
private var interval: Duration

private let onTimeout: @Sendable () async -> Void
private var onTimeout: (isolated (any Actor)?) async -> Void
private var item: Task<(), Never>?

public init(
interval: DispatchTimeInterval,
@_inheritActorContext onTimeout: @escaping @Sendable () async -> Void
interval: Duration,
onTimeout: sending @escaping () async -> Void
) {

self.interval = interval
self.onTimeout = onTimeout

refresh()
self.onTimeout = { a in
await onTimeout()
}

}

public mutating func tap() {
refresh()
public func tap(isolation: isolated (any Actor)? = #isolation) {
refresh(isolation: isolation)
}

private mutating func refresh() {
private func refresh(isolation: isolated (any Actor)? = #isolation) {

self.item?.cancel()

let task = Task { [onTimeout, interval] in

try? await Task.sleep(nanoseconds: interval.makeNanoseconds())
try? await Task.sleep(for: interval)

guard Task.isCancelled == false else { return }

await onTimeout()
await onTimeout(isolation)
}

self.item = task
}

}

extension DispatchTimeInterval {

fileprivate func makeNanoseconds() -> UInt64 {

switch self {
case .nanoseconds(let v): return UInt64(v)
case .microseconds(let v): return UInt64(v) * 1_000
case .milliseconds(let v): return UInt64(v) * 1_000_000
case .seconds(let v): return UInt64(v) * 1_000_000_000
case .never: return UInt64.max
@unknown default:
assertionFailure()
return 0
}

}

}
Loading

0 comments on commit 4f9a344

Please sign in to comment.