Skip to content

Queue delay not working as expected #25

Description

@mdktdys

For some reason, adding a function to the queue causes the previous one to end. Am I doing something wrong or is this intended? How can I get the expected result?

import 'dart:async';
import 'dart:developer';

import 'package:queue/src/dart_queue_base.dart';

void main() async {

  final Queue queue = Queue(delay: Duration(seconds: 6));

  Future<void> wait(String a) async {
    await queue.add(() => Future.delayed(Duration(milliseconds: 100)));
    log('$a ${DateTime.now()}');
  };

  wait('a');
  wait('b');
  await Future.delayed(Duration(milliseconds: 100));
  wait('c');


  await Future.delayed(Duration(seconds: 10));
}

result:
[log] a 2025-03-06 16:12:24.307348
[log] b 2025-03-06 16:12:24.412779
[log] c 2025-03-06 16:12:30.432560

excepted:
[log] a 2025-03-06 16:12:24.307348
[log] b 2025-03-06 16:12:30.332560
[log] c 2025-03-06 16:12:36.432560

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions