Skip to content

Commit

Permalink
Swift 4: Make SyncSinkTarget a class
Browse files Browse the repository at this point in the history
... fix concurrent memory access issue.
  • Loading branch information
helje5 committed Mar 12, 2018
1 parent d8bf4e3 commit 681e129
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Sources/streams/adaptors/SinkTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public protocol SinkType { // 2beta4 has no SinkType anymore
mutating func put(_ x: Self.Element)
}

public struct SyncSinkTarget<S: SinkType> : GWritableTargetType {
public class SyncSinkTarget<S: SinkType> : GWritableTargetType {

public static var defaultHighWaterMark : Int { return 1 }

Expand All @@ -28,7 +28,7 @@ public struct SyncSinkTarget<S: SinkType> : GWritableTargetType {
self.target = target
}

private mutating func _writev(chunks : [ [ S.Element ] ]) -> Int {
private func _writev(chunks : [ [ S.Element ] ]) -> Int {
var count = 0

for bucket in chunks {
Expand All @@ -40,9 +40,9 @@ public struct SyncSinkTarget<S: SinkType> : GWritableTargetType {
return count
}

public mutating func writev(queue q : DispatchQueue,
chunks : [ [ S.Element ] ],
yield : @escaping ( Error?, Int ) -> Void)
public func writev(queue q : DispatchQueue,
chunks : [ [ S.Element ] ],
yield : @escaping ( Error?, Int ) -> Void)
{
let count = _writev(chunks: chunks)
yield(nil, count)
Expand Down
2 changes: 1 addition & 1 deletion Tests/streamsTests/BasicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NozeIOBasicTests: XCTestCase {

func testSinkTarget() {
let Q = core.Q
var target = SyncSinkTarget<NumberPrinter>(NumberPrinter())
let target = SyncSinkTarget<NumberPrinter>(NumberPrinter())

target.writev(queue: Q, chunks: [ [ 10 ] ] ) { _, writeCount in
print(" * wrote: \(writeCount)")
Expand Down

0 comments on commit 681e129

Please sign in to comment.