PollingTask class

轮询任务管理器 PollingTask

说明

统一管理应用中的多个定时轮询型任务,适用于定时刷新、定期检查等场景。 提供任务的启动、停止、全部停止、运行状态检查及任务ID获取的统一入口。

单例用法

final polling = PollingTask();
// 或直接 PollingTask().start(...)

常用方法

  • start 启动新的轮询任务
  • stop 停止指定ID的任务
  • stopAll 停止所有任务
  • isRunning 检查任务是否运行中
  • runningIds 获取所有正在运行的任务ID列表

Constructors

PollingTask()
工厂方法,确保全局唯一实例
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runningIds List<String>
获取所有当前正在运行任务的ID列表
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

isRunning(String id) bool
检查指定ID的任务是否正在运行中
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start({required String id, required Duration interval, required VoidCallback onTick, bool restartIfExists = true}) → void
启动一个新的轮询任务
stop(String id) → void
停止指定ID的轮询任务
stopAll() → void
停止所有轮询任务
toString() String
A string representation of this object.
inherited

Operators

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