Future - Async Programming
std::future มี traits พื้นฐานสำหรับ asynchronous programming ใน Rust โดยให้ abstraction สำหรับค่าที่จะพร้อมใช้งานในอนาคต ทำให้เขียน non-blocking code ได้อย่างปลอดภัยและมีประสิทธิภาพ
Future คืออะไร?
Section titled “Future คืออะไร?”Future คือ representation ของ computation ที่อาจยังไม่เสร็จ แตกต่างจากการ block thread รอผลลัพธ์ Future ช่วยให้ program ทำงานอื่นได้ระหว่างรอ
หลักการสำคัญของ Future:
async fnreturn Future โดยอัตโนมัติ- ใช้
.awaitเพื่อรอผลลัพธ์แบบ non-blocking - ไม่ block thread ทำให้ handle concurrent operations ได้มาก
- Lazy execution - ไม่ทำงานจนกว่าจะถูก poll
เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google