I'm trying to run 3 functions serially having each function complete before the next one starts. The below code works fine but I get three warnings on the try await [one, two, three]
line:
try
expressionasync
operations occur within await
expression[()]
is unused.Any suggestions on the proper way to code this and not get these warnings?
Task {
let one: () = await func1()
let two: () = await func2()
let three: () = await func3()
try await [one, two, three]
}
func func1() async { ... }
func func2() async { ... }
func func3() async { ... }
The functions essentially decode JSON data from separate external sources and then calculations are done on the results so its important each decoding happens before the next one starts.
It is simply:
Task {
await func1()
await func2()
await func3()
}
That will run them consecutively. Just be wary of introducing additional unstructured concurrency (Task {…}
) in those functions.