Created
December 25, 2021 12:25
-
-
Save SergLam/e648d52a54246020684964d8ab3edf05 to your computer and use it in GitHub Desktop.
AsyncSequence extension to iterate elements in a synchronous-like way
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
import Foundation | |
extension AsyncSequence { | |
func forEach(_ body: (Element) async throws -> Void) async throws { | |
for try await element in self { | |
try await body(element) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment