(request: T)
| 21 | } |
| 22 | |
| 23 | request(request: T): Promise<any> { |
| 24 | const hash = this.options.batchBy(request) |
| 25 | if (!hash) { |
| 26 | return this.options.singleLoader(request) |
| 27 | } |
| 28 | if (!this.batches[hash]) { |
| 29 | this.batches[hash] = [] |
| 30 | |
| 31 | // make sure, that we only tick once at a time |
| 32 | if (!this.tickActive) { |
| 33 | this.tickActive = true |
| 34 | process.nextTick(() => { |
| 35 | this.dispatchBatches() |
| 36 | this.tickActive = false |
| 37 | }) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return new Promise((resolve, reject) => { |
| 42 | this.batches[hash].push({ |
| 43 | request, |
| 44 | resolve, |
| 45 | reject, |
| 46 | }) |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | private dispatchBatches() { |
| 51 | for (const key in this.batches) { |
nothing calls this directly
no test coverage detected