Skip to content

Commit 923c6aa

Browse files
committed
Remove '|undefined' from abortSignal/abortPromise
1 parent 61da707 commit 923c6aa

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

__tests__/getTasks.test.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import { makeMockJob, withPgClient } from "./helpers";
1010

1111
const options: WorkerSharedOptions = {};
1212

13+
const neverAbortController = new AbortController();
14+
const abortSignal = neverAbortController.signal;
15+
const abortPromise = new Promise<void>((_, reject) => {
16+
abortSignal.addEventListener("abort", reject);
17+
});
18+
1319
describe("commonjs", () => {
1420
test("gets tasks from folder", () =>
1521
withPgClient(async (client) => {
@@ -32,8 +38,8 @@ Array [
3238
withPgClient: makeEnhancedWithPgClient(
3339
makeWithPgClientFromClient(client),
3440
),
35-
abortSignal: undefined,
36-
abortPromise: undefined,
41+
abortSignal,
42+
abortPromise,
3743
},
3844
);
3945
expect(await tasks.wouldyoulike!(helpers.job.payload, helpers)).toEqual(
@@ -69,8 +75,8 @@ Array [
6975
withPgClient: makeEnhancedWithPgClient(
7076
makeWithPgClientFromClient(client),
7177
),
72-
abortSignal: undefined,
73-
abortPromise: undefined,
78+
abortSignal,
79+
abortPromise,
7480
},
7581
);
7682
expect(await tasks.task1!(helpers.job.payload, helpers)).toEqual("hi");
@@ -100,8 +106,8 @@ Array [
100106
withPgClient: makeEnhancedWithPgClient(
101107
makeWithPgClientFromClient(client),
102108
),
103-
abortSignal: undefined,
104-
abortPromise: undefined,
109+
abortSignal,
110+
abortPromise,
105111
},
106112
);
107113
expect(await tasks.task1!(helpers.job.payload, helpers)).toEqual("hi");
@@ -130,8 +136,8 @@ Array [
130136
withPgClient: makeEnhancedWithPgClient(
131137
makeWithPgClientFromClient(client),
132138
),
133-
abortSignal: undefined,
134-
abortPromise: undefined,
139+
abortSignal,
140+
abortPromise,
135141
});
136142
expect(await tasks.t1!(helpers.job.payload, helpers)).toEqual(
137143
"come with me",
@@ -161,8 +167,8 @@ Array [
161167
withPgClient: makeEnhancedWithPgClient(
162168
makeWithPgClientFromClient(client),
163169
),
164-
abortSignal: undefined,
165-
abortPromise: undefined,
170+
abortSignal,
171+
abortPromise,
166172
});
167173
expect(await tasks.t1!(helpers.job.payload, helpers)).toEqual(
168174
"come with me, TS",
@@ -196,8 +202,8 @@ Array [
196202
withPgClient: makeEnhancedWithPgClient(
197203
makeWithPgClientFromClient(client),
198204
),
199-
abortSignal: undefined,
200-
abortPromise: undefined,
205+
abortSignal,
206+
abortPromise,
201207
},
202208
);
203209
expect(await tasks.wouldyoulike!(helpers.job.payload, helpers)).toEqual(
@@ -230,8 +236,8 @@ Array [
230236
withPgClient: makeEnhancedWithPgClient(
231237
makeWithPgClientFromClient(client),
232238
),
233-
abortSignal: undefined,
234-
abortPromise: undefined,
239+
abortSignal,
240+
abortPromise,
235241
},
236242
);
237243
expect(await tasks.task1!(helpers.job.payload, helpers)).toEqual("hi");
@@ -258,8 +264,8 @@ Array [
258264
withPgClient: makeEnhancedWithPgClient(
259265
makeWithPgClientFromClient(client),
260266
),
261-
abortSignal: undefined,
262-
abortPromise: undefined,
267+
abortSignal,
268+
abortPromise,
263269
});
264270
expect(await tasks.t1!(helpers.job.payload, helpers)).toEqual(
265271
"come with me",

src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ export function makeJobHelpers(
229229
logger: overrideLogger,
230230
}: {
231231
withPgClient: EnhancedWithPgClient;
232-
abortSignal: AbortSignal | undefined;
233-
abortPromise: Promise<void> | undefined;
232+
abortSignal: AbortSignal;
233+
abortPromise: Promise<void>;
234234
logger?: Logger;
235235
},
236236
): JobHelpers {

src/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ export interface JobHelpers extends Helpers {
185185
*
186186
* @experimental
187187
*/
188-
abortSignal: AbortSignal | undefined;
188+
abortSignal: AbortSignal;
189189

190190
/**
191191
* A promise that rejects when the AbortSignal aborts.
192192
*
193193
* @experimental
194194
*/
195-
abortPromise: Promise<void> | undefined;
195+
abortPromise: Promise<void>;
196196
}
197197

198198
export type CleanupTask =

0 commit comments

Comments
 (0)