addJob method Null safety

  1. @override
void addJob(
  1. AsyncJob job,
  2. {String? label,
  3. String? description,
  4. int retryTime = 1}
)

Add new job into the queue

retryTime set the time that this job should retry if failed, default to 1, set retryTime to -1 will make it retry infinitely, until job is done "be careful what you wish for!" setting retryTime does not make the job auto retry you must explicitly call retry when adding job. label must be unique, this can be use to get the AsyncNode that contains the related job will throw DuplicatedLabelException if you the label is already in the queue description description for the job

Implementation

@override
void addJob(
  AsyncJob job, {
  String? label,
  String? description,
  int retryTime = 1,
}) {
  if (isClosed) {
    return _emitEvent(QueueEventType.violateAddWhenClosed);
  }

  final newNode = AsyncNode(
    job: job,
    maxRetry: retryTime,
    label: label ?? DateTime.now().toIso8601String(),
    description: description,
  );

  if (_map.containsKey(newNode.label)) {
    throw DuplicatedLabelException("A job with this label already exists");
  }
  _map[newNode.label] = newNode;
  _enqueue(newNode);

  if (_autoRun) start();
}