iOS

Concurrency & async/await

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

26 питань зі співбесід·
Senior
1

What is an async function in Swift?

Відповідь

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?

Відповідь

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?

Відповідь

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 питань зі співбесід

Опануй iOS для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно