Skip to content

Commit

Permalink
Revert "Fix processing chain interface (#556)"
Browse files Browse the repository at this point in the history
This reverts commit 795c0fd.
  • Loading branch information
hiroshihorie committed Jan 25, 2025
1 parent 25674aa commit 181d212
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing-matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
cancel-in-progress: true

env:
TESTS: "FunctionTests ProcessingChainTests SDKTests RoomTests PublishDataTests PublishBufferCapturerTests VideoViewTests TrackTests"
TESTS: "FunctionTests SDKTests RoomTests PublishDataTests PublishBufferCapturerTests VideoViewTests TrackTests"

jobs:
test:
Expand Down
3 changes: 1 addition & 2 deletions Sources/LiveKit/Protocols/ChainedProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import Foundation

public protocol ChainedProcessor: AnyObject {
associatedtype NextProcessorType: ChainedProcessor
// Next object in the chain.
var nextProcessor: NextProcessorType? { get set }
var nextProcessor: Self? { get set }
}
6 changes: 3 additions & 3 deletions Sources/LiveKit/Support/ProcessingChain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

public class ProcessingChain<T: ChainedProcessor> {
public class ProcessingChain<T: ChainedProcessor>: NSObject, Loggable {
// MARK: - Public properties

public var isProcessorsEmpty: Bool { countProcessors == 0 }
Expand Down Expand Up @@ -61,15 +61,15 @@ public class ProcessingChain<T: ChainedProcessor> {
guard !processors.isEmpty else { return nil }

for i in 0 ..< (processors.count - 1) {
processors[i].nextProcessor = processors[i + 1] as? T.NextProcessorType
processors[i].nextProcessor = processors[i + 1]
}
// The last one doesn't have a successor
processors.last?.nextProcessor = nil

return processors.first
}

public func invokeChain<R>(_ fnc: @escaping (T) -> R) -> R? {
public func invokeProcessor<R>(_ fnc: @escaping (T) -> R) -> R? {
guard let chain = buildProcessorChain() else { return nil }
return fnc(chain)
}
Expand Down
8 changes: 2 additions & 6 deletions Tests/LiveKitTests/ProcessingChainTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
@testable import LiveKit
import XCTest

protocol MockProcessingInterface: ChainedProcessor {
func process(value: Int) -> Int
}

class ProcessingChainTests: XCTestCase {
// Mock processor for testing
class MockProcessor: MockProcessingInterface {
final class MockProcessor: NSObject, ChainedProcessor {
weak var nextProcessor: MockProcessor?

func process(value: Int) -> Int {
Expand Down Expand Up @@ -115,7 +111,7 @@ class ProcessingChainTests: XCTestCase {
chain.add(processor: processor2)
chain.add(processor: processor3)

let result = chain.invokeChain { $0.process(value: 0) }
let result = chain.invokeProcessor { $0.process(value: 0) }

// Each processor adds 1, so with 3 processors the final result should be 3
XCTAssertEqual(result, 3)
Expand Down

0 comments on commit 181d212

Please sign in to comment.