Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it feasible to change priority of a Queued item on the fly #208

Open
Raishav opened this issue Jul 3, 2024 · 1 comment
Open

Is it feasible to change priority of a Queued item on the fly #208

Raishav opened this issue Jul 3, 2024 · 1 comment

Comments

@Raishav
Copy link

Raishav commented Jul 3, 2024

I'm working on a custom loader with asynchronous load promises, I want to change the priority of a specific promise function, can this be achieved using current code?

I managed to achieve something by queuing up the promise function again with updated priority, but this loads the item twice.

prioritize(key: string) {
    const promise = this.taskList.get(key);
    if (!promise) {
      console.error("No such promise: ", key);
    } else {
      this.pause();
      this.queue.add(promise, { priority: 2 });
      this.resume();
    }
}

Thanks.

@sindresorhus
Copy link
Owner

There could maybe be a .setPriority(fn, {priority}) method that could accept the original function you passed to .add() (for ID purposes) and let you change the priority.

RaishavHanspal added a commit to RaishavHanspal/p-queue that referenced this issue Jul 10, 2024
RaishavHanspal added a commit to RaishavHanspal/p-queue that referenced this issue Jul 10, 2024
RaishavHanspal added a commit to RaishavHanspal/p-queue that referenced this issue Jul 11, 2024
RaishavHanspal added a commit to RaishavHanspal/p-queue that referenced this issue Jul 12, 2024
RaishavHanspal added a commit to RaishavHanspal/p-queue that referenced this issue Jul 18, 2024
RaishavHanspal added a commit to RaishavHanspal/p-queue that referenced this issue Jul 19, 2024
RaishavHanspal added a commit to RaishavHanspal/p-queue that referenced this issue Jul 19, 2024
RaishavHanspal added a commit to RaishavHanspal/p-queue that referenced this issue Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants