-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved improper usages of assertRejects to assertThrows for non async …
…test assertions
- Loading branch information
1 parent
ad5b0f0
commit 9cabbd5
Showing
26 changed files
with
239 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,10 @@ | |
/// <reference lib="deno.ns" /> | ||
|
||
import { assert } from "https://deno.land/[email protected]/assert/assert.ts"; | ||
import { assertRejects } from "https://deno.land/[email protected]/assert/assert_rejects.ts"; | ||
import { List } from "./List.ts"; | ||
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts"; | ||
import { Deferred, deferred } from "./async/Deferred.ts"; | ||
import { assertThrows } from "./index.ts"; | ||
|
||
Deno.test("List groupBy function test", () => { | ||
const list = new List(1, 2, 3, 4, 5); | ||
|
@@ -43,9 +43,9 @@ Deno.test("List instanceOf test", () => { | |
assert(list instanceof List); | ||
}); | ||
|
||
Deno.test("List readonly write error test", async () => { | ||
Deno.test("List readonly write error test", () => { | ||
const list = List.readonly(1, 2, 3, 4, 5); | ||
await assertRejects(async () => { | ||
assertThrows(() => { | ||
(list as any).push(6); | ||
}); | ||
assert(list instanceof List); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type IterableLike<T> = | ||
| readonly T[] | ||
| readonly PromiseLike<T>[] | ||
| AsyncGenerator<T> | ||
| AsyncIterable<T> | ||
| Iterable<T> | ||
| Iterable<PromiseLike<T>> | ||
| PromiseLike<readonly T[]> | ||
| PromiseLike<readonly PromiseLike<T>[]> | ||
| PromiseLike<AsyncIterable<T>> | ||
| PromiseLike<Iterable<T>> | ||
| PromiseLike<Iterable<PromiseLike<T>>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import { QueueLengthExceededError } from "../errors/QueueLengthExceededError.ts" | |
import { ShutdownError } from "../errors/ShutdownError.ts"; | ||
import { assert } from "https://deno.land/[email protected]/assert/assert.ts"; | ||
import { createCancellation } from "../cancellation/createCancellation.ts"; | ||
import { assertThrows } from "../index.ts"; | ||
|
||
Deno.test("JobPool test", async () => { | ||
let counter = 0; | ||
|
@@ -81,9 +82,8 @@ Deno.test("JobPool fail max queue test", async () => { | |
promises.push(pool.submit(() => sig.wait())); | ||
promises.push(pool.submit(() => sig.wait())); | ||
|
||
await assertRejects( | ||
// deno-lint-ignore require-await | ||
async () => { | ||
assertThrows( | ||
() => { | ||
promises.push(pool.submit(() => sig.wait())); | ||
}, | ||
QueueLengthExceededError | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,22 +5,22 @@ | |
/// <reference lib="deno.ns" /> | ||
|
||
import { assert } from "https://deno.land/[email protected]/assert/assert.ts"; | ||
import { Executor } from "./executors.ts"; | ||
import { executors } from "./executors.ts"; | ||
import { monitor } from "./Monitor.ts"; | ||
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts"; | ||
import { signal } from "./Signal.ts"; | ||
import { delay } from "./delay.ts"; | ||
|
||
Deno.test("executor immediate test", () => { | ||
let hasRun = false; | ||
Executor.immediate.execute(() => { | ||
executors.immediate.execute(() => { | ||
hasRun = true; | ||
}); | ||
assert(hasRun); | ||
}); | ||
|
||
Deno.test("executor sequential test", async () => { | ||
const executor = Executor.sequential(); | ||
const executor = executors.sequential(); | ||
const c = monitor(); | ||
|
||
let counter = -1; | ||
|
@@ -34,7 +34,7 @@ Deno.test("executor sequential test", async () => { | |
|
||
executor.execute(async () => { | ||
if (index % 3 === 0) { | ||
await Executor.macro.execute(increment); | ||
await executors.macro.execute(increment); | ||
} else { | ||
increment(); | ||
} | ||
|
@@ -48,7 +48,7 @@ Deno.test("executor sequential test", async () => { | |
}); | ||
|
||
Deno.test("executor task/micro/seqential", async () => { | ||
const executor = Executor.sequential(); | ||
const executor = executors.sequential(); | ||
const c = monitor(); | ||
|
||
let counter = -1; | ||
|
@@ -62,9 +62,9 @@ Deno.test("executor task/micro/seqential", async () => { | |
|
||
executor.execute(async () => { | ||
if (index % 3 === 0) { | ||
await Executor.macro.execute(increment); | ||
await executors.macro.execute(increment); | ||
} else if (index % 3 === 1) { | ||
await Executor.micro.execute(increment); | ||
await executors.micro.execute(increment); | ||
} else { | ||
increment(); | ||
} | ||
|
@@ -79,7 +79,7 @@ Deno.test("executor task/micro/seqential", async () => { | |
|
||
Deno.test("executor concurrent", async () => { | ||
let counter = 0; | ||
const executor = Executor.concurrent(3); | ||
const executor = executors.concurrent(3); | ||
|
||
const sig = signal(); | ||
for (let i = 0; i < 10; i++) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Callable } from "../types.ts"; | ||
import type { CancellationToken } from "../cancellation/CancellationToken.ts"; | ||
|
||
/** | ||
* An abstraction for executing tasks. | ||
*/ | ||
export interface Executor { | ||
/** | ||
* @param callable The task to execute. | ||
* @param deadline The deadline for the task to complete. | ||
* @returns A promise that resolves with the result of the callable or rejects with an error. | ||
*/ | ||
execute: <T>( | ||
callable: Callable<T | PromiseLike<T>>, | ||
deadline?: CancellationToken, | ||
) => Promise<T>; | ||
} | ||
|
||
/** | ||
* An executor that executes tasks concurrently. | ||
*/ | ||
export interface ConcurrentExecutor extends Executor { | ||
/** | ||
* Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. | ||
* Invocation has no additional effect if already shut down. | ||
* @returns A promise that resolves when the executor has completed shutdown. | ||
*/ | ||
shutdown(): void; | ||
|
||
/** | ||
* Awaits completion of all tasks in the executor. | ||
* @returns A promise that resolves when the executor has completed shutdown. | ||
*/ | ||
onShutdown(): Promise<void>; | ||
|
||
/** | ||
* @returns `true` if the executor has initiated shutdown. | ||
*/ | ||
readonly isShutdownInitiated: boolean; | ||
|
||
/** | ||
* @returns `true` if the executor has completed shutdown. | ||
*/ | ||
readonly isShutdown: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.