Skip to content

Commit

Permalink
Merge pull request #109 from Milly/revert-refresh-target-check
Browse files Browse the repository at this point in the history
fix: revert refresh target check in cancel
  • Loading branch information
Shougo authored Apr 15, 2024
2 parents 39bc2b7 + a728059 commit a64ce3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
6 changes: 2 additions & 4 deletions denops/ddu/ddu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
AvailableSourceInfo,
GatherState,
GatherStateAbortable,
isRefreshTarget,
} from "./state.ts";
import {
callColumns,
Expand Down Expand Up @@ -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;
}
Expand Down
19 changes: 9 additions & 10 deletions denops/ddu/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -149,7 +148,7 @@ export class GatherState<
}
}

function isRefreshTarget(
export function isRefreshTarget(
sourceIndex: number,
refreshIndexes: number[],
): boolean {
Expand Down

0 comments on commit a64ce3e

Please sign in to comment.