Skip to content

Commit 06953e6

Browse files
authored
refactor(computation): rename cancel to abort (#4639)
1 parent 1db6071 commit 06953e6

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

src/execution/incremental/Computation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ type MaybePromise<T> =
99
/** @internal **/
1010
export class Computation<T> {
1111
private _fn: () => PromiseOrValue<T>;
12-
private _onCancel: ((reason?: unknown) => void) | undefined;
12+
private _onAbort: ((reason?: unknown) => void) | undefined;
1313
private _maybePromise?: MaybePromise<T>;
1414
constructor(
1515
fn: () => PromiseOrValue<T>,
16-
onCancel?: (reason?: unknown) => void,
16+
onAbort?: (reason?: unknown) => void,
1717
) {
1818
this._fn = fn;
19-
this._onCancel = onCancel;
19+
this._onAbort = onAbort;
2020
}
2121
prime(): MaybePromise<T> {
2222
if (this._maybePromise) {
@@ -54,7 +54,7 @@ export class Computation<T> {
5454
}
5555
}
5656
}
57-
cancel(reason?: unknown): void {
57+
abort(reason?: unknown): void {
5858
const maybePromise = this._maybePromise;
5959
if (!maybePromise) {
6060
this._maybePromise = {
@@ -64,8 +64,8 @@ export class Computation<T> {
6464
return;
6565
}
6666
const status = maybePromise.status;
67-
if (status === 'pending' && this._onCancel) {
68-
this._onCancel(reason);
67+
if (status === 'pending' && this._onAbort) {
68+
this._onAbort(reason);
6969
this._maybePromise = {
7070
status: 'rejected',
7171
reason,

src/execution/incremental/IncrementalExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class IncrementalExecutor<
321321
override cancel(reason?: unknown): void {
322322
super.cancel(reason);
323323
for (const task of this.tasks) {
324-
task.computation.cancel(reason);
324+
task.computation.abort(reason);
325325
}
326326
for (const stream of this.streams) {
327327
const aborted = stream.queue.abort(reason);
@@ -594,7 +594,7 @@ export class IncrementalExecutor<
594594
const filteredTasks: Array<ExecutionGroup> = [];
595595
for (const task of tasks) {
596596
if (collectedErrors.hasNulledPosition(task.path)) {
597-
task.computation.cancel(cancellationReason);
597+
task.computation.abort(cancellationReason);
598598
} else {
599599
filteredTasks.push(task);
600600
}

src/execution/incremental/WorkQueue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export function createWorkQueue<
282282
reason: unknown,
283283
cancelPromises: Array<Promise<unknown>>,
284284
): void {
285-
task.computation.cancel(reason);
285+
task.computation.abort(reason);
286286
const taskNode = taskNodes.get(task);
287287
if (taskNode) {
288288
for (const childStream of taskNode.childStreams) {

src/execution/incremental/__tests__/Computation-test.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,93 +106,93 @@ describe('Computation', () => {
106106
expect(runCount).to.equal(1);
107107
});
108108

109-
it('can be cancelled before running', () => {
110-
let onCancelRan = false;
109+
it('can be aborted before running', () => {
110+
let onAbortRan = false;
111111
const computation = new Computation(
112112
() => ({ value: 123 }),
113113
() => {
114-
onCancelRan = true;
114+
onAbortRan = true;
115115
},
116116
);
117-
computation.cancel();
117+
computation.abort();
118118
expect(() => computation.result()).to.throw('Cancelled!');
119-
expect(onCancelRan).to.equal(false);
119+
expect(onAbortRan).to.equal(false);
120120
});
121121

122-
it('cannot be cancelled after running synchronously', () => {
123-
let onCancelRan = false;
122+
it('cannot be aborted after running synchronously', () => {
123+
let onAbortRan = false;
124124
const computation = new Computation(
125125
() => ({ value: 123 }),
126126
() => {
127-
onCancelRan = true;
127+
onAbortRan = true;
128128
},
129129
);
130130

131131
computation.prime();
132-
computation.cancel();
132+
computation.abort();
133133
expect(computation.result()).to.deep.equal({ value: 123 });
134-
expect(onCancelRan).to.equal(false);
134+
expect(onAbortRan).to.equal(false);
135135
});
136136

137-
it('cannot be cancelled after erroring synchronously', () => {
138-
let onCancelRan = false;
137+
it('cannot be aborted after erroring synchronously', () => {
138+
let onAbortRan = false;
139139
const computation = new Computation(
140140
() => {
141141
throw new Error('failure');
142142
},
143143
() => {
144-
onCancelRan = true;
144+
onAbortRan = true;
145145
},
146146
);
147147

148148
computation.prime();
149-
computation.cancel();
149+
computation.abort();
150150
expect(() => computation.result()).to.throw('failure');
151-
expect(onCancelRan).to.equal(false);
151+
expect(onAbortRan).to.equal(false);
152152
});
153153

154-
it('can be cancelled while running asynchronously', () => {
155-
let onCancelRan = false;
154+
it('can be aborted while running asynchronously', () => {
155+
let onAbortRan = false;
156156
const computation = new Computation(
157157
() =>
158158
new Promise(() => {
159159
// Never resolves.
160160
}),
161161
() => {
162-
onCancelRan = true;
162+
onAbortRan = true;
163163
},
164164
);
165165

166166
computation.prime();
167-
computation.cancel();
168-
expect(onCancelRan).to.equal(true);
167+
computation.abort();
168+
expect(onAbortRan).to.equal(true);
169169
expect(() => computation.result()).to.throw('Cancelled!');
170170
});
171171

172-
it('can be cancelled with a provided reason before running', () => {
172+
it('can be aborted with a provided reason before running', () => {
173173
const abortReason = new Error('aborted');
174174
const computation = new Computation(() => ({ value: 123 }));
175175

176-
computation.cancel(abortReason);
176+
computation.abort(abortReason);
177177
expect(() => computation.result()).to.throw('aborted');
178178
});
179179

180-
it('forwards cancellation reason to onCancel while running asynchronously', () => {
180+
it('forwards abort reason to onAbort while running asynchronously', () => {
181181
const abortReason = new Error('aborted');
182-
let onCancelReason: unknown;
182+
let onAbortReason: unknown;
183183
const computation = new Computation(
184184
() =>
185185
new Promise(() => {
186186
// Never resolves.
187187
}),
188188
(reason) => {
189-
onCancelReason = reason;
189+
onAbortReason = reason;
190190
},
191191
);
192192

193193
computation.prime();
194-
computation.cancel(abortReason);
195-
expect(onCancelReason).to.equal(abortReason);
194+
computation.abort(abortReason);
195+
expect(onAbortReason).to.equal(abortReason);
196196
expect(() => computation.result()).to.throw('aborted');
197197
});
198198
});

0 commit comments

Comments
 (0)