admin管理员组文章数量:1026989
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:
- No calls to throwing functions occur within
try
expression - No
async
operations occur withinawait
expression - Expression of type
[()]
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.
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:
- No calls to throwing functions occur within
try
expression - No
async
operations occur withinawait
expression - Expression of type
[()]
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.
Share Improve this question edited Nov 16, 2024 at 18:44 Alexander 63.5k13 gold badges105 silver badges168 bronze badges asked Nov 16, 2024 at 2:55 user1233894user1233894 1,7761 gold badge12 silver badges11 bronze badges 1 |1 Answer
Reset to default 1It 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.
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:
- No calls to throwing functions occur within
try
expression - No
async
operations occur withinawait
expression - Expression of type
[()]
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.
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:
- No calls to throwing functions occur within
try
expression - No
async
operations occur withinawait
expression - Expression of type
[()]
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.
Share Improve this question edited Nov 16, 2024 at 18:44 Alexander 63.5k13 gold badges105 silver badges168 bronze badges asked Nov 16, 2024 at 2:55 user1233894user1233894 1,7761 gold badge12 silver badges11 bronze badges 1-
These 3 functions are suspicious: if it's important that they run in a specific order, why is it that none of them take input, or return a result? Most people would expect to see something like
let one = await func1()
,let two = await func2(one)
,let three = await func3(two)
. That would make the dependency obvious, and impossible to get wrong. – Alexander Commented Nov 16, 2024 at 18:46
1 Answer
Reset to default 1It 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.
本文标签: swiftRunning 3 functions serially each running when the previous function completesStack Overflow
版权声明:本文标题:swift - Running 3 functions serially each running when the previous function completes - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745667692a2162270.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
let one = await func1()
,let two = await func2(one)
,let three = await func3(two)
. That would make the dependency obvious, and impossible to get wrong. – Alexander Commented Nov 16, 2024 at 18:46