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

consecutive calls shows just first one #40

Open
dengue8830 opened this issue Oct 23, 2019 · 2 comments
Open

consecutive calls shows just first one #40

dengue8830 opened this issue Oct 23, 2019 · 2 comments

Comments

@dengue8830
Copy link

Problem

if i call the notification two or more times consecutively it renders just the first one. If i use a timeout for the second one i get a good behaviour.

Proposal

I'm thinking implement a delayed queue in order to show consecutive calls in a queued way and show them one by one with a timeout. Do you accept a pull request for this?

@robcalcroft
Copy link
Owner

robcalcroft commented Oct 23, 2019 via email

@dengue8830
Copy link
Author

dengue8830 commented Oct 23, 2019

I will try to add this feature next week, by the moment i used this code (if someone find it useful) in my project

This is a resume of the real code

function timeout(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

class NotificationService {
    // you can call this one several times
    show(notif) {
          this.queue.push(notif);
          this.evaluateQueue();
    }

    async evaluateQueue() {
      if (!this.queue.length || this.isEvaluationProcessLocked) {
        return;
      }
      this.isEvaluationProcessLocked = true;
      // We can use a recursive approach too
      while (this.queue.length) {
        this._show(this.queue.splice(0, 1)[0]); // the real showNotification api
        await timeout(4000); // closeInterval, check docs of this lib
      }
      this.isEvaluationProcessLocked = false;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants