(fn: () => Promise<T> | T, { priority }: { priority?: boolean } = {})
| 66 | } |
| 67 | |
| 68 | add(fn: () => Promise<T> | T, { priority }: { priority?: boolean } = {}) { |
| 69 | return new Promise<any>((resolve, reject) => { |
| 70 | const task = () => |
| 71 | Promise.resolve(fn()) |
| 72 | .then((res) => { |
| 73 | resolve(res) |
| 74 | return res |
| 75 | }) |
| 76 | .catch((err) => { |
| 77 | reject(err) |
| 78 | throw err |
| 79 | }) |
| 80 | if (priority) { |
| 81 | this.pending.unshift(task) |
| 82 | } else { |
| 83 | this.pending.push(task) |
| 84 | } |
| 85 | this.tick() |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | throttle(n: number) { |
| 90 | this.currentConcurrency = n |
no test coverage detected