Skip to content

Commit 11fcbb4

Browse files
committed
refactor: rename types to match Tokio naming conventions
1 parent 3e16ceb commit 11fcbb4

4 files changed

Lines changed: 25 additions & 24 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
## Why Antiox?
1616

17-
- **Zero cost:** No custom DSL, no wrapper types, no extra allocations, and no dependencies. Intentionally does not implement `Result`, `Option`, or `match` — TypeScript's `T | null`, union types, and `switch` already cover these at zero cost.
17+
- **Async primitives:** Channels, streams, select, tasks, and more. Everything you need for structured concurrency and backpressure in TypeScript.
18+
- **Lightweight** No custom DSL, no wrapper types, no unnecessary allocations, and no dependencies. Intentionally does not implement `Result`, `Option`, or `match`. TypeScript's `T | null`, union types, and `switch` already cover these at zero cost.
1819
- **Rust-shaped:** The control flow and concurrency patterns you miss from Rust, mapped onto native JS primitives. Because let's be honest, you wish you were writing Rust instead.
1920
- **Lightweight:** Every module is tree-shakeable and tiny enough to ship as a transitive dependency without burdening downstream consumers.
2021

@@ -406,9 +407,9 @@ guard.disarm(); // or prevent cleanup
406407
Priority queue-backed channel. Messages received in priority order.
407408

408409
```typescript
409-
import { priorityChannel } from "antiox/sync/priority_channel";
410+
import { channel } from "antiox/sync/priority_channel";
410411

411-
const [tx, rx] = priorityChannel<number>();
412+
const [tx, rx] = channel<number>();
412413
tx.send(3);
413414
tx.send(1);
414415
tx.send(2);

src/mod.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export {
2727
} from "./sync/mpsc";
2828

2929
export {
30-
priorityChannel,
31-
PrioritySender,
32-
PriorityReceiver,
30+
channel as priorityChannel,
31+
Sender as PrioritySender,
32+
Receiver as PriorityReceiver,
3333
} from "./sync/priority_channel";
3434
export type { TrySendErrorKind, TryRecvErrorKind } from "./sync/mpsc";
3535

src/sync/priority_channel.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ interface PriorityChannelState<T> {
5252
* @param compare - Comparator function. Positive return means `a` has higher
5353
* priority. Defaults to max-ordering for numbers/strings.
5454
*/
55-
export function priorityChannel<T>(
55+
export function channel<T>(
5656
compare?: (a: T, b: T) => number,
57-
): [PrioritySender<T>, PriorityReceiver<T>] {
57+
): [Sender<T>, Receiver<T>] {
5858
const state: PriorityChannelState<T> = {
5959
heap: new BinaryHeap(compare),
6060
closed: false,
6161
senderCount: 1,
6262
recvWaiters: [],
6363
};
64-
return [new PrioritySender(state), new PriorityReceiver(state)];
64+
return [new Sender(state), new Receiver(state)];
6565
}
6666

6767
/** Sending half of a priority channel. */
68-
export class PrioritySender<T> {
68+
export class Sender<T> {
6969
#state: PriorityChannelState<T>;
7070
#dropped = false;
7171

@@ -96,10 +96,10 @@ export class PrioritySender<T> {
9696
}
9797

9898
/** Clone this sender. */
99-
clone(): PrioritySender<T> {
100-
if (this.#dropped) throw new Error("Cannot clone a dropped PrioritySender");
99+
clone(): Sender<T> {
100+
if (this.#dropped) throw new Error("Cannot clone a dropped Sender");
101101
this.#state.senderCount++;
102-
return new PrioritySender(this.#state);
102+
return new Sender(this.#state);
103103
}
104104

105105
/** Drop this sender. When all senders drop, receiver gets null. */
@@ -121,7 +121,7 @@ export class PrioritySender<T> {
121121
}
122122

123123
/** Receiving half of a priority channel. Messages arrive in priority order. */
124-
export class PriorityReceiver<T> {
124+
export class Receiver<T> {
125125
#state: PriorityChannelState<T>;
126126
#closed = false;
127127

tests/sync/priority_channel.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { describe, it, expect } from "vitest";
22
import {
3-
priorityChannel,
4-
PrioritySender,
5-
PriorityReceiver,
3+
channel,
4+
Sender,
5+
Receiver,
66
TryRecvError,
77
} from "../../src/sync/priority_channel";
88

9-
describe("priorityChannel", () => {
9+
describe("channel", () => {
1010
it("messages received in priority order (highest first)", async () => {
11-
const [tx, rx] = priorityChannel<number>();
11+
const [tx, rx] = channel<number>();
1212
tx.send(1);
1313
tx.send(5);
1414
tx.send(3);
@@ -19,7 +19,7 @@ describe("priorityChannel", () => {
1919
});
2020

2121
it("custom comparator (min-heap)", async () => {
22-
const [tx, rx] = priorityChannel<number>((a, b) => {
22+
const [tx, rx] = channel<number>((a, b) => {
2323
if (a < b) return 1;
2424
if (a > b) return -1;
2525
return 0;
@@ -34,7 +34,7 @@ describe("priorityChannel", () => {
3434
});
3535

3636
it("multi-producer via clone", async () => {
37-
const [tx1, rx] = priorityChannel<number>();
37+
const [tx1, rx] = channel<number>();
3838
const tx2 = tx1.clone();
3939

4040
tx1.send(3);
@@ -47,7 +47,7 @@ describe("priorityChannel", () => {
4747
});
4848

4949
it("disconnection: sender close -> recv returns null after drain", async () => {
50-
const [tx, rx] = priorityChannel<number>();
50+
const [tx, rx] = channel<number>();
5151
tx.send(10);
5252
tx.send(20);
5353
tx.close();
@@ -58,7 +58,7 @@ describe("priorityChannel", () => {
5858
});
5959

6060
it("tryRecv success and errors", () => {
61-
const [tx, rx] = priorityChannel<number>();
61+
const [tx, rx] = channel<number>();
6262

6363
expect(() => rx.tryRecv()).toThrow(TryRecvError);
6464
try {
@@ -80,7 +80,7 @@ describe("priorityChannel", () => {
8080
});
8181

8282
it("async iterator works", async () => {
83-
const [tx, rx] = priorityChannel<number>();
83+
const [tx, rx] = channel<number>();
8484
tx.send(1);
8585
tx.send(3);
8686
tx.send(2);

0 commit comments

Comments
 (0)