generated from rafaelesantos/swift-readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d47071
commit 146ef4e
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ | |
|
||
"welcomeIntroduction" = "Welcome to"; | ||
|
||
// MARK: - Task | ||
|
||
"refdsTask" = "refds.task.%@"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,7 @@ | |
// MARK: - Welcome | ||
|
||
"welcomeIntroduction" = "Bem-vindo(a) ao"; | ||
|
||
// MARK: - Task | ||
|
||
"refdsTask" = "refds.task.%@"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |