What is the difference between launch/join and async/await in Kotlin coroutines?
What is the difference between launch/join and async/await in Kotlin coroutines?
The main differences between launch/join and async/await in Kotlin coroutines are:
launch returns a Job and is used to start a coroutine that doesn't return a result, while async returns a Deferred<T> and is used to start a coroutine that computes and returns a result.
join() is used to wait for a coroutine started with launch to complete, while await() is used to retrieve the result of a coroutine started with async.
If an exception occurs in a coroutine started with launch, it is propagated and can crash the application if not handled. With async, exceptions are stored in the Deferred and must be explicitly handled.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.