IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
930B

  1. //
  2. // Copyright (C) Stanislaw Adaszewski, 2020
  3. // Contact: s.adaszewski@gmail.com
  4. // Website: https://adared.ch/wba
  5. // License: GNU Affero General Public License, Version 3
  6. //
  7. class WBManifestWorkerWrapper {
  8. constructor() {
  9. this.worker = new Worker('/js/wb-manifest-worker.js');
  10. this.worker.onmessage = e => this.onMessage(e);
  11. this.worker.onerror = e => console.log(e);
  12. this.queue = [];
  13. }
  14. onMessage(e) {
  15. if (this.queue.length === 0)
  16. throw Error('Unexpected message from worker');
  17. const [msgType, accept, reject] = this.queue.splice(0, 1)[0];
  18. if (e.data[0] === msgType + 'Result')
  19. accept(e);
  20. else
  21. reject(e);
  22. }
  23. postMessage(m) {
  24. const prom = new Promise((accept, reject) => {
  25. this.queue.push([ m[0], accept, reject ]);
  26. this.worker.postMessage(m);
  27. });
  28. return prom;
  29. }
  30. }
  31. export default WBManifestWorkerWrapper;