Last active
April 29, 2019 14:41
-
-
Save CognitiveDisson/ac772024dfd3f00c466ed035b4b0fbbc to your computer and use it in GitHub Desktop.
Revisions
-
CognitiveDisson revised this gist
Apr 29, 2019 . 1 changed file with 7 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import Foundation public extension Array { public func asyncConcurrentEnumerated( each: (_ object: Element, _ completion: @escaping () -> (), _ stop: () -> ()) throws -> ()) throws { let dispatchGroup = DispatchGroup() let array = NSArray(array: self) @@ -15,10 +15,9 @@ public extension Array { do { try each( object, { dispatchGroup.leave() }, { stop.pointee = true dispatchGroup.leave() } ) @@ -29,6 +28,8 @@ public extension Array { } } dispatchGroup.wait() if let error = eachError { throw error } } } -
CognitiveDisson revised this gist
Apr 29, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,14 @@ import Foundation public extension Array { public func asyncConcurrentEnumerated( each: (_ object: Element, _ completion: (Bool) -> ()) throws -> ()) -> Error? { let dispatchGroup = DispatchGroup() let array = NSArray(array: self) var eachError: Error? array.enumerateObjects(options: .concurrent) { obj, key, stop in guard let object = obj as? Element else { return } dispatchGroup.enter() -
CognitiveDisson revised this gist
Apr 29, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ import Foundation public extension Array { public func asyncConcurrentEnumerated<T>( each: (_ object: T, _ completion: (Bool) -> ()) throws -> ()) -> Error? { let dispatchGroup = DispatchGroup() -
CognitiveDisson created this gist
Apr 29, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import Foundation extension Array { func asyncConcurrentEnumerated<T>( each: (_ object: T, _ completion: (Bool) -> ()) throws -> ()) -> Error? { let dispatchGroup = DispatchGroup() let array = NSArray(array: self) var eachError: Error? array.enumerateObjects(options: .concurrent) { obj, key, stop in guard let object = obj as? T else { return } dispatchGroup.enter() do { try each( object, { stopValue in if stopValue == true { stop.pointee = true } dispatchGroup.leave() } ) } catch { eachError = error stop.pointee = true dispatchGroup.leave() } } dispatchGroup.wait() return eachError } }