Overview
- I have a function
f1
which is non-async function.
f1
gets called multiple times and I have no control over the calling of f1
- When f1 gets called I would like to invoke an async function
f2
Aim:
- I would like
f2
to complete before the next f2
executes
Question:
- How can I ensure
f2
executes in sequence? (sample code below)
//I have no control over f1
//f1 can get called multiple times in quick succession.
func f1() {
Task {
try await f2() // Next time f1 gets called it should wait for the previous f2 to complete then should execute f2
}
}
func f2() async throws {}