Câu hỏi phỏng vấn Kotlin
Câu hỏi

What is the difference between launch/jo...

Câu trả lời

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[1][4][5].

  • 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[1][2][3].

  • 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[4][5].

  • launch is useful for fire-and-forget tasks that don't need to return a value, while async is better for tasks that compute a result that will be used later[1][4].

  • Both launch and async can be used to...

expert

expert

Gợi ý câu hỏi phỏng vấn

middle

What is the difference between suspending vs. blocking?

junior

What is basic difference between fold and reduce in Kotlin? When to use which?

middle

What is the purpose of Unit-returning in functions? Why is VALUE there? What is this V ALUE ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào