iOS

Concurrency & async/await

async/await, Task, actors, MainActor, structured concurrency, task groups, cancellation

26 pertanyaan wawancaraยท
Senior
1

What is an async function in Swift?

Jawaban

An async function is one that can suspend and resume without blocking the thread. It uses the async keyword to indicate it can await asynchronous operations with await. The Swift compiler automatically generates code to manage the suspension state, allowing other tasks to execute during waits.

2

What is the role of the await keyword in Swift?

Jawaban

The await keyword marks a potential suspension point where a function can be suspended while waiting for an asynchronous operation result. It signals to the compiler and Swift runtime that the execution context may change at this point, allowing the system to execute other tasks during the wait. This is fundamental to Swift's cooperative concurrency model.

3

What is a Task in Swift concurrency?

Jawaban

A Task is a unit of asynchronous work that represents an independent executing operation. It encapsulates an asynchronous operation and manages its lifecycle, enabling async code to be launched from a synchronous context.

4

What is the difference between Task and Task.detached?

5

How to use async let for concurrency?

+23 pertanyaan wawancara

Kuasai iOS untuk wawancara berikutnya

Akses semua pertanyaan, flashcards, tes teknis, latihan code review dan simulator wawancara.

Mulai gratis