Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Quiz: บทที่ 16 - Async/Await

คำถาม 16.1

async fn return อะไร?

A. ค่าตรงๆ
B. Future
C. Promise
D. Task

ดูเฉลย

B. Future

async fn fetch() -> String {
    // return impl Future<Output = String>
    String::from("data")
}

คำถาม 16.2

.await ทำอะไร?

A. หยุด program
B. รอให้ Future complete
C. สร้าง thread
D. Cancel operation

ดูเฉลย

B. รอให้ Future complete

let data = fetch().await;
```text

</details>

---

# คำถาม 16.3

Tokio คืออะไร?

A. Web framework  
B. Async runtime  
C. Database  
D. Testing tool

<details>
<summary>ดูเฉลย</summary>

**B. Async runtime**

Tokio รัน async code และจัดการ tasks

</details>

---

# คำถาม 16.4

`tokio::spawn` ใช้ทำอะไร?

A. สร้าง thread  
B. สร้าง async task  
C. หยุด task  
D. Join tasks

<details>
<summary>ดูเฉลย</summary>

**B. สร้าง async task**

```rust,ignore
tokio::spawn(async {
    // background task
});
```text

</details>

---

# คำถาม 16.5

`tokio::join!` ทำอะไร?

A. รวม strings  
B. รอหลาย futures พร้อมกัน  
C. สร้าง channel  
D. Lock mutex

<details>
<summary>ดูเฉลย</summary>

**B. รอหลาย futures พร้อมกัน**

```rust,ignore
let (a, b) = tokio::join!(task1(), task2());

👉 Quiz บทที่ 17