Latest<K> class

A utility to handle async tasks with Last-In-Wins policy. คลาสช่วยจัดการงานแบบ Latest-Only เหมาะกับกรณีที่ต้องการรันงานซ้ำๆ แต่สนใจแค่ผลลัพธ์ล่าสุดเท่านั้น เช่น การดึงข้อมูลจาก API ที่ต้องการแค่ผลลัพธ์ล่าสุด โดยงานเก่าจะถูกยกเลิกทันทีที่มีงานใหม่เข้ามาแทนที่ ตัวอย่างการใช้งาน:

final latest = Latest<String>();
latest<int>(
  key: 'fetchData',
  task: () async {
    // ดึงข้อมูลจาก API
    return await fetchDataFromApi();
  },
  onSuccess: (data) {
    // อัพเดต UI ด้วยข้อมูลที่ได้
  },
  onError: (error) {
    // จัดการข้อผิดพลาด
  },
);

Constructors

Latest()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call<T>({required K key, required Future<T> task(), required void onSuccess(T data), void onError(Object error)?}) → void
cancelAll() → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited