Skip to content
เข้าสู่ระบบ

Future - Async Programming

std::future มี traits พื้นฐานสำหรับ asynchronous programming ใน Rust โดยให้ abstraction สำหรับค่าที่จะพร้อมใช้งานในอนาคต ทำให้เขียน non-blocking code ได้อย่างปลอดภัยและมีประสิทธิภาพ

Future คือ representation ของ computation ที่อาจยังไม่เสร็จ แตกต่างจากการ block thread รอผลลัพธ์ Future ช่วยให้ program ทำงานอื่นได้ระหว่างรอ

หลักการสำคัญของ Future:

  • async fn return Future โดยอัตโนมัติ
  • ใช้ .await เพื่อรอผลลัพธ์แบบ non-blocking
  • ไม่ block thread ทำให้ handle concurrent operations ได้มาก
  • Lazy execution - ไม่ทำงานจนกว่าจะถูก poll

เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม

ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด