Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active March 6, 2024 02:35
Show Gist options
  • Save benigumocom/99ca9f1ff7ef8998add916393a8ba352 to your computer and use it in GitHub Desktop.
Save benigumocom/99ca9f1ff7ef8998add916393a8ba352 to your computer and use it in GitHub Desktop.
【Swift】非同期関数の直列実行 - withCheckedContinuation 👉 https://android.benigumo.com/20240305/sereial-async/
import SwiftUI
import AVFoundation
struct TestView: View {
var body: some View {
Button("Play1") {
AudioServicesPlaySystemSound(1000)
}
Divider()
Button("Play2") {
AudioServicesPlaySystemSound(SystemSoundID(1000))
}
Divider()
Button("Play3") {
for i in 1000...1010 {
AudioServicesPlaySystemSound(SystemSoundID(i))
}
}
Divider()
Button("Play4") {
AudioServicesPlaySystemSoundWithCompletion(SystemSoundID(1000)) {
print("completed.")
}
}
Divider()
Button("Play5") {
Task {
for i in 1000...1010 {
await withCheckedContinuation { continuation in
AudioServicesPlaySystemSoundWithCompletion(SystemSoundID(i)) {
continuation.resume()
}
}
}
}
}
}
}
#Preview {
TestView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment