Skip to content

Instantly share code, notes, and snippets.

@SergLam
Created December 25, 2021 12:25
Show Gist options
  • Save SergLam/e648d52a54246020684964d8ab3edf05 to your computer and use it in GitHub Desktop.
Save SergLam/e648d52a54246020684964d8ab3edf05 to your computer and use it in GitHub Desktop.
AsyncSequence extension to iterate elements in a synchronous-like way
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