* Unsubscribes an observer from the query. * @internal * @param observer - The observer to remove. When the last observer is removed, the in-flight * fetch is cancelled if its abort signal was consumed (otherwise only its retries are stopped), * and garbage collection is scheduled.
(observer: QueryObserver<any, any, any, any, any>)
| 634 | * and garbage collection is scheduled. |
| 635 | */ |
| 636 | removeObserver(observer: QueryObserver<any, any, any, any, any>): void { |
| 637 | const index = this.observers.indexOf(observer) |
| 638 | if (index !== -1) { |
| 639 | this.observers.splice(index, 1) |
| 640 | |
| 641 | if (!this.observers.length) { |
| 642 | // If the transport layer does not support cancellation |
| 643 | // we'll let the query continue so the result can be cached |
| 644 | if (this.#retryer) { |
| 645 | if ( |
| 646 | this.#abortSignalConsumed || |
| 647 | (this.state.fetchStatus === 'paused' && |
| 648 | this.state.status === 'pending') |
| 649 | ) { |
| 650 | this.#retryer.cancel({ revert: true }) |
| 651 | } else { |
| 652 | this.#retryer.cancelRetry() |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | this.scheduleGc() |
| 657 | } |
| 658 | |
| 659 | this.#cache.notify({ type: 'observerRemoved', query: this, observer }) |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | /** |
| 664 | * Returns the number of observers currently subscribed to this query. |
no test coverage detected