()
| 534 | } |
| 535 | |
| 536 | private async driveSort() { |
| 537 | while (true) { |
| 538 | if (this.sorting || !this.pending) { |
| 539 | return; // Sort already in process or nothing to sort |
| 540 | } |
| 541 | |
| 542 | const { viewToWorld, displayed } = this.pending; |
| 543 | let accumulator = this.pending.accumulator; |
| 544 | if (!accumulator) { |
| 545 | // Hold a reference to the accumulator while sorting |
| 546 | accumulator = this.display?.accumulator ?? this.spark.active; |
| 547 | accumulator.refCount += 1; |
| 548 | } |
| 549 | this.pending = null; |
| 550 | if (!accumulator) { |
| 551 | throw new Error("No accumulator to sort"); |
| 552 | } |
| 553 | |
| 554 | this.sorting = { viewToWorld }; |
| 555 | await this.sortUpdate({ accumulator, viewToWorld, displayed }); |
| 556 | this.sorting = null; |
| 557 | |
| 558 | // Release the reference to the accumulator |
| 559 | this.spark.releaseAccumulator(accumulator); |
| 560 | |
| 561 | // Continue in loop with any queued sort |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | private async sortUpdate({ |
| 566 | accumulator, |
no test coverage detected