Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sync/mpsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class Sender<T> {
}

isClosed(): boolean {
return this.#state.closed;
return this.#dropped || this.#state.closed;
}

capacity(): number {
Expand Down Expand Up @@ -373,7 +373,7 @@ export class UnboundedSender<T> {
}

isClosed(): boolean {
return this.#state.closed;
return this.#dropped || this.#state.closed;
}

clone(): UnboundedSender<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/sync/oneshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class OneshotSender<T> {
}

isClosed(): boolean {
return this.#state.receiverClosed;
return this.#dropped || this.#state.receiverClosed;
}

closed(signal?: AbortSignal): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/sync/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class WatchSender<T> {
}

isClosed(): boolean {
return this.#state.receiverCount === 0;
return this.#closed || this.#state.receiverCount === 0;
}

close(): void {
Expand Down
14 changes: 14 additions & 0 deletions tests/sync/mpsc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ describe("bounded channel", () => {
expect(tx.isClosed()).toBe(true);
});

it("isClosed is true after sender close", () => {
const [tx, rx] = channel<number>(8);
tx.close();
expect(tx.isClosed()).toBe(true);
void rx;
});

it("closed() resolves when receiver closes", async () => {
const [tx, rx] = channel<number>(8);
let resolved = false;
Expand Down Expand Up @@ -512,6 +519,13 @@ describe("unbounded channel", () => {
expect(tx.isClosed()).toBe(true);
});

it("isClosed is true after sender close", () => {
const [tx, rx] = unboundedChannel<number>();
tx.close();
expect(tx.isClosed()).toBe(true);
void rx;
});

it("closed() resolves when receiver closes", async () => {
const [tx, rx] = unboundedChannel<number>();
let resolved = false;
Expand Down
7 changes: 7 additions & 0 deletions tests/sync/oneshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ describe("oneshot", () => {
expect(tx.isClosed()).toBe(true);
});

it("isClosed is true after sender close", () => {
const [tx, rx] = oneshot<number>();
tx[Symbol.dispose]();
expect(tx.isClosed()).toBe(true);
void rx;
});

it("isClosed is false after send (sender closed but receiver is not)", () => {
const [tx, rx] = oneshot<number>();
tx.send(1);
Expand Down
7 changes: 7 additions & 0 deletions tests/sync/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ describe("watch", () => {
expect(tx.isClosed()).toBe(true);
});

it("isClosed is true after sender close", () => {
const [tx, rx] = watch(0);
tx.close();
expect(tx.isClosed()).toBe(true);
void rx;
});

it("sendIfModified returns true and wakes receivers when predicate returns true", async () => {
const [tx, rx] = watch({ count: 0 });
rx.borrowAndUpdate();
Expand Down
Loading