Skip to content

queue.add runs the future immediately, why? #28

@burekas7

Description

@burekas7

@rknell

Hi,

What could be the reason that when I add a Future to the queue using add, it immediately runs the Future?

I didn’t put an await before queue.add.

I want to collect all of them first, and only when I run onComplete, I want them to execute one after another.

For example:

  static Future<void> Function() createOfflineQueueTask({
    required Future<void> Function() apiCall,
  }) {
    return () async {
      print("Executing offline API call...");
      await apiCall();
      print("Finished executing offline API call...");
    };
  }

apiCall is Future<T?> Function()

queue.add(createOfflineQueueTask(apiCall: apiCall);

And when I want to run them:

queue.onComplete.then((_) {
      remainingItemsStream.close();
      queue?.dispose();
    });

But thequeue.add runs them immediately instead before running the onComplete, why?

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