Last active
March 6, 2024 02:35
-
-
Save benigumocom/99ca9f1ff7ef8998add916393a8ba352 to your computer and use it in GitHub Desktop.
【Swift】非同期関数の直列実行 - withCheckedContinuation 👉 https://android.benigumo.com/20240305/sereial-async/
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 characters
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