Skip to content

Commit

Permalink
Add task implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelesantos committed Aug 21, 2024
1 parent 0d47071 commit 146ef4e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public enum RefdsLocalizableKey: String {
case riskHighDescription
case riskWarningDescription
case welcomeIntroduction
case refdsTask
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@

"welcomeIntroduction" = "Welcome to";

// MARK: - Task

"refdsTask" = "refds.task.%@";
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@
// MARK: - Welcome

"welcomeIntroduction" = "Bem-vindo(a) ao";

// MARK: - Task

"refdsTask" = "refds.task.%@";
32 changes: 32 additions & 0 deletions Sources/RefdsShared/Task/RefdsTask.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Foundation

public final class RefdsTask {
private let group = DispatchGroup()
private let queue: DispatchQueue

static let shared = RefdsTask()

public init(
label: String = .someWord(),
qos: DispatchQoS = .unspecified,
attributes: DispatchQueue.Attributes = .concurrent
) {
queue = DispatchQueue(
label: .refdsLocalizable(by: .refdsTask, with: label),
qos: qos,
attributes: attributes
)
}

public typealias ExecuteItem = () -> Void
public func execute(items: [ExecuteItem]) {
items.forEach { item in
group.enter()
queue.async {
item()
self.group.leave()
}
}
group.wait()
}
}

0 comments on commit 146ef4e

Please sign in to comment.