diff --git a/denops/ddu/ddu.ts b/denops/ddu/ddu.ts index 5b4b9e3..8ab008f 100644 --- a/denops/ddu/ddu.ts +++ b/denops/ddu/ddu.ts @@ -40,6 +40,7 @@ import { AvailableSourceInfo, GatherState, GatherStateAbortable, + isRefreshTarget, } from "./state.ts"; import { callColumns, @@ -884,10 +885,7 @@ export class Ddu { await Promise.all( [...this.#gatherStates] .map(([sourceIndex, state]) => { - if ( - (refreshIndexes.length === 0 || - refreshIndexes.includes(sourceIndex)) && state.signal.aborted - ) { + if (isRefreshTarget(sourceIndex, refreshIndexes)) { this.#gatherStates.delete(sourceIndex); return state.waitDone; } diff --git a/denops/ddu/state.ts b/denops/ddu/state.ts index 2fe2f86..4562fd5 100644 --- a/denops/ddu/state.ts +++ b/denops/ddu/state.ts @@ -50,24 +50,22 @@ export class GatherState< ) { const { signal: parentSignal } = options ?? {}; this.sourceInfo = sourceInfo; - if (parentSignal) { - this.#chainAbortSignal(parentSignal); - } + this.#chainAbortSignal(parentSignal); this.itemsStream = this.#processItemsStream(itemsStream); } resetSignal(signal?: AbortSignal): void { // Do nothing if already aborted. if (!this.#aborter.signal.aborted) { - this.#resetParentSignal?.abort(); - if (signal != null) { - this.#chainAbortSignal(signal); - } + this.#chainAbortSignal(signal); } } - #chainAbortSignal(parentSignal: AbortSignal): void { - this.#resetParentSignal = new AbortController(); + #chainAbortSignal(parentSignal?: AbortSignal): void { + this.#resetParentSignal?.abort(); + if (parentSignal == null) { + return; + } const abortIfTarget = () => { const reason = maybe( @@ -85,6 +83,7 @@ export class GatherState< if (parentSignal.aborted) { abortIfTarget(); } else { + this.#resetParentSignal = new AbortController(); parentSignal.addEventListener("abort", () => abortIfTarget(), { signal: AbortSignal.any([ this.#aborter.signal, @@ -149,7 +148,7 @@ export class GatherState< } } -function isRefreshTarget( +export function isRefreshTarget( sourceIndex: number, refreshIndexes: number[], ): boolean {