| 682 | return weak_results.get(promiseGenerator) |
| 683 | } |
| 684 | static enqueueNew(task, classCtor, progressCallback) { |
| 685 | if (task.status !== TaskStatus.init) { |
| 686 | throw new Error("Task has an invalid status to add to queue.") |
| 687 | } |
| 688 | if (!(task instanceof classCtor)) { |
| 689 | throw new Error("Task is not a instance of classCtor.") |
| 690 | } |
| 691 | let promiseGenerator = undefined |
| 692 | if (typeof progressCallback === "undefined") { |
| 693 | promiseGenerator = classCtor.start(task) |
| 694 | } else if (typeof progressCallback === "function") { |
| 695 | promiseGenerator = classCtor.start(task, progressCallback) |
| 696 | } else { |
| 697 | throw new Error("progressCallback is not a function.") |
| 698 | } |
| 699 | return Task.prototype.enqueue.call(task, promiseGenerator) |
| 700 | } |
| 701 | |
| 702 | static async run(promiseGenerator, { callback, signal, timeout = -1 } = {}) { |
| 703 | let value = undefined |