Skip to content

Commit

Permalink
Update RefdsTask.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelesantos committed Aug 22, 2024
1 parent 17956e3 commit 0e2d333
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Sources/RefdsShared/Task/RefdsTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Foundation

public protocol RefdsTaskProtocol {
typealias ExecuteItem = () -> Void
func execute(items: [ExecuteItem])
func concurrent(items: [ExecuteItem])
func sequential(items: [ExecuteItem])
}

public final class RefdsTask: RefdsTaskProtocol {
Expand All @@ -23,7 +24,7 @@ public final class RefdsTask: RefdsTaskProtocol {
)
}

public func execute(items: [ExecuteItem]) {
public func concurrent(items: [ExecuteItem]) {
items.forEach { item in
group.enter()
queue.async {
Expand All @@ -33,4 +34,15 @@ public final class RefdsTask: RefdsTaskProtocol {
}
group.wait()
}

public func sequential(items: [ExecuteItem]) {
items.forEach { item in
group.enter()
queue.async {
item()
self.group.leave()
}
group.wait()
}
}
}

0 comments on commit 0e2d333

Please sign in to comment.