enqueue method

String enqueue(
  1. String method,
  2. String url, {
  3. Map<String, String>? headers,
  4. dynamic body,
})

Adds a request to the queue

Implementation

String enqueue(
  String method,
  String url, {
  Map<String, String>? headers,
  dynamic body,
}) {
  // Remove oldest request if queue is full
  if (_queue.length >= maxSize) {
    _queue.removeFirst();
  }

  final id =
      'req_${_requestCounter++}_${DateTime.now().millisecondsSinceEpoch}';
  final request = QueuedRequest(
    id: id,
    method: method,
    url: url,
    timestamp: DateTime.now(),
    headers: headers,
    body: body,
  );

  _queue.add(request);
  return id;
}