enqueue<T> method

Future<T> enqueue<T>(
  1. Future<T> executor(), {
  2. RequestPriority priority = RequestPriority.normal,
  3. String? tag,
})

添加请求到队列

Implementation

Future<T> enqueue<T>(
  Future<T> Function() executor, {
  RequestPriority priority = RequestPriority.normal,
  String? tag,
}) {
  // 如果队列未启用,直接执行
  if (!_enabled) {
    return executor();
  }

  final request = QueuedRequest<T>(
    id: DateTime.now().microsecondsSinceEpoch.toString(),
    executor: executor,
    priority: priority,
    tag: tag,
  );

  _pendingQueue.add(request);
  _sortQueue();
  _notifyQueueChange();
  _processQueue();

  return request.completer.future;
}