Skip to content

Commit

Permalink
Rename synchronous to initInBackground (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas34 authored May 6, 2019
1 parent 71456ee commit a2c3a6f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Sources/SwiftQueue/SqOperationQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal final class SqOperationQueue: OperationQueue {
private let trigger: Operation

init(_ queueName: String, _ creator: JobCreator, _ persister: JobPersister, _ serializer: JobInfoSerializer,
_ isSuspended: Bool, _ synchronous: Bool, _ logger: SwiftQueueLogger) {
_ isSuspended: Bool, _ initInBackground: Bool, _ logger: SwiftQueueLogger) {

self.queueName = queueName

Expand All @@ -46,12 +46,12 @@ internal final class SqOperationQueue: OperationQueue {
self.name = queueName
self.maxConcurrentOperationCount = 1

if synchronous {
self.loadSerializedTasks(name: queueName)
} else {
if initInBackground {
DispatchQueue.global(qos: DispatchQoS.QoSClass.utility).async { () -> Void in
self.loadSerializedTasks(name: queueName)
}
} else {
self.loadSerializedTasks(name: queueName)
}
}

Expand Down
19 changes: 13 additions & 6 deletions Sources/SwiftQueue/SwiftQueueManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class SwiftQueueManager {
self.isSuspended = params.isSuspended

for queueName in persister.restore() {
manage[queueName] = SqOperationQueue(queueName, creator, persister, serializer, isSuspended, params.synchronous, logger)
manage[queueName] = SqOperationQueue(queueName, creator, persister, serializer, isSuspended, params.initInBackground, logger)
}
}

Expand All @@ -57,7 +57,7 @@ public final class SwiftQueueManager {

private func createQueue(queueName: String) -> SqOperationQueue {
// At this point the queue should be totally new so it's safe to start the queue synchronously
let queue = SqOperationQueue(queueName, creator, persister, serializer, isSuspended, true, logger)
let queue = SqOperationQueue(queueName, creator, persister, serializer, isSuspended, false, logger)
manage[queueName] = queue
return queue
}
Expand Down Expand Up @@ -120,21 +120,21 @@ internal class SqManagerParams {

var isSuspended: Bool

var synchronous: Bool
var initInBackground: Bool

init(creator: JobCreator,
persister: JobPersister = UserDefaultsPersister(),
serializer: JobInfoSerializer = DecodableSerializer(),
logger: SwiftQueueLogger = NoLogger.shared,
isSuspended: Bool = false,
synchronous: Bool = true) {
initInBackground: Bool = false) {

self.creator = creator
self.persister = persister
self.serializer = serializer
self.logger = logger
self.isSuspended = isSuspended
self.synchronous = synchronous
self.initInBackground = initInBackground
}

}
Expand Down Expand Up @@ -176,8 +176,15 @@ public final class SwiftQueueManagerBuilder {
}

/// Deserialize jobs synchronously after creating the `SwiftQueueManager` instance. `true` by default
@available(*, deprecated, renamed: "initInBackground")
public func set(synchronous: Bool) -> Self {
params.synchronous = synchronous
params.initInBackground = !synchronous
return self
}

/// Deserialize jobs synchronously after creating the `SwiftQueueManager` instance. `true` by default
public func set(initInBackground: Bool) -> Self {
params.initInBackground = initInBackground
return self
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftQueueTests/PersisterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class PersisterTests: XCTestCase {
tasks[lastTaskType] = lastJob

let creator = TestCreator(tasks)
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: persister).set(synchronous: false).build()
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: persister).set(initInBackground: true).build()

JobBuilder(type: lastTaskType)
.singleInstance(forId: lastTaskType)
Expand Down

0 comments on commit a2c3a6f

Please sign in to comment.