Skip to content

Commit

Permalink
Merge pull request #110 from Milly/fix-signal-period
Browse files Browse the repository at this point in the history
fix: Fix by considering the period of signal
  • Loading branch information
Shougo authored Apr 21, 2024
2 parents 21cb759 + 2cafd0f commit ec18cb9
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions denops/ddu/ddu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,24 +247,25 @@ export class Ddu {
this.#resetQuitted();
this.#startTime = Date.now();

// NOTE: Get the signal after the aborter is reset.
const { signal } = this.#aborter;

// Gather items asynchronously.
const [availableSources, sourcesInitialized] = this
.#createAvailableSourceStream(denops, { initialize: true })
.tee();
const [gatherStates] = availableSources
.pipeThrough(this.#createGatherStateTransformer(denops))
.pipeThrough(this.#createGatherStateTransformer(denops, signal))
.tee();

// Wait until initialized all sources. Source onInit() must be called before UI.
await Array.fromAsync(sourcesInitialized);

// UI should load before refresh.
// NOTE: If UI is blocked until refresh, user input will break UI.
await this.uiRedraw(denops, { signal: this.#aborter.signal });
await this.uiRedraw(denops, { signal });

await this.#refreshSources(denops, gatherStates, {
signal: this.#aborter.signal,
});
await this.#refreshSources(denops, gatherStates, { signal });

this.#initialized = true;
}
Expand Down Expand Up @@ -313,14 +314,17 @@ export class Ddu {

await this.cancelToRefresh(refreshIndexes);

// NOTE: Get the signal after the aborter is reset.
const { signal } = this.#aborter;

// Initialize UI window
if (!this.#options.sync) {
/* no await */ this.redraw(denops);
}

const [gatherStates] = this
.#createAvailableSourceStream(denops, { indexes: refreshIndexes })
.pipeThrough(this.#createGatherStateTransformer(denops))
.pipeThrough(this.#createGatherStateTransformer(denops, signal))
.tee();

await this.#refreshSources(denops, gatherStates);
Expand Down Expand Up @@ -381,6 +385,7 @@ export class Ddu {

#createGatherStateTransformer(
denops: Denops,
signal: AbortSignal,
): TransformStream<AvailableSourceInfo, GatherState> {
return new TransformStream({
transform: (sourceInfo, controller) => {
Expand All @@ -394,7 +399,7 @@ export class Ddu {
sourceParams,
this.#loader,
0,
{ signal: this.#aborter.signal },
{ signal },
);
this.#gatherStates.set(sourceIndex, state);

Expand Down Expand Up @@ -983,6 +988,9 @@ export class Ddu {
});
}

// NOTE: Get the signal after the UI action finishes.
const { signal } = this.#aborter;

const flags = typeof ret === "number" ? ret : ActionFlags.None;

if (flags & ActionFlags.RefreshItems) {
Expand All @@ -996,7 +1004,7 @@ export class Ddu {
ui,
uiOptions,
uiParams,
this.#aborter.signal,
signal,
);
}
}
Expand Down Expand Up @@ -1125,6 +1133,9 @@ export class Ddu {
// Restore quitted flag before refresh and redraw
this.#resetQuitted();

// NOTE: Get the signal after the aborter is reset.
const { signal } = this.#aborter;

if (ui) {
await uiRedraw(
denops,
Expand All @@ -1134,7 +1145,7 @@ export class Ddu {
ui,
uiOptions,
uiParams,
this.#aborter.signal,
signal,
);
}
}
Expand Down

0 comments on commit ec18cb9

Please sign in to comment.