iOS

Concurrency & async/await

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

26 câu hỏi phỏng vấn·
Senior
1

What is an async function in Swift?

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững iOS cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí