Skip to content

Commit

Permalink
Merge pull request #3 from yoheimuta/fix-misc-signature
Browse files Browse the repository at this point in the history
Add @escaping to the write method
  • Loading branch information
yoheimuta authored Jul 30, 2018
2 parents e00bfff + 9c64a18 commit 4690fc6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions BufferedLogger/BufferedOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ final class BufferedOutput {
var chunk = chunk
chunk.incrementRetryCount()

if chunk.retryCount <= config.retryRule.retryLimit {
let delay = config.retryRule.delay(try: chunk.retryCount)
queue.asyncAfter(deadline: .now() + delay) {
if chunk.retryCount <= self.config.retryRule.retryLimit {
let delay = self.config.retryRule.delay(try: chunk.retryCount)
self.queue.asyncAfter(deadline: .now() + delay) {
self.callWriteChunk(chunk)
}
}
Expand Down
11 changes: 6 additions & 5 deletions BufferedLogger/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import Foundation

/// Entry represents an entity to be written by a writer.
public struct Entry: Codable, Hashable {
/// createdDate is the date the entry is created.
public var createdDate: Date
/// createTime is the date the entry is created.
public let createTime: Date

/// payload is a log content.
public let payload: Data

private let identifier: UUID = UUID()
/// identifier is an unique entry ID.
public let identifier: UUID = UUID()

public var hashValue: Int {
return identifier.hashValue
Expand All @@ -26,8 +27,8 @@ public struct Entry: Codable, Hashable {
return lhs.identifier == rhs.identifier
}

init(_ payload: Data, createdDate: Date = Date()) {
init(_ payload: Data, createTime: Date = Date()) {
self.payload = payload
self.createdDate = createdDate
self.createTime = createTime
}
}
2 changes: 1 addition & 1 deletion BufferedLogger/Writer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public protocol Writer {
/// - Parameters:
/// - chunk: a set of log entries
/// - completion: call with true when the write action is success.
func write(_ chunk: Chunk, completion: (Bool) -> Void)
func write(_ chunk: Chunk, completion: @escaping (Bool) -> Void)
}
2 changes: 1 addition & 1 deletion BufferedLoggerTests/BufferedOutputTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class MockWriter: Writer {
}

func write(_ chunk: Chunk,
completion: (Bool) -> Void) {
completion: @escaping (Bool) -> Void) {
calledWriteCount += 1
chunk.entries.forEach {
givenPayloads.append($0.payload)
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/MyWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import BufferedLogger
import Foundation

class MyWriter: Writer {
func write(_ chunk: Chunk, completion: (Bool) -> Void) {
func write(_ chunk: Chunk, completion: @escaping (Bool) -> Void) {
print("chunk is \(chunk)")

chunk.entries.forEach {
Expand Down

0 comments on commit 4690fc6

Please sign in to comment.