1
0

make async equality collections sync iterables

This commit is contained in:
2024-05-13 22:39:59 +02:00
parent eda8c8cf5d
commit 1f8e8039b6
3 changed files with 26 additions and 26 deletions

View File

@@ -1,5 +1,4 @@
import { Equater, MaybeAsyncEquater } from "./types.js";
import { asAsyncGenerator } from "./utils.js";
export interface EqualitySet<T> extends Iterable<T> {
readonly size: number;
@@ -106,12 +105,12 @@ export function createEqualitySet<T>(equater?: Equater<T>): EqualitySet<T> {
return equater ? new CustomEqualitySet(equater) : new NativeEqualitySet<T>();
}
export interface AsyncEqualitySet<T> extends AsyncIterable<T> {
export interface AsyncEqualitySet<T> extends Iterable<T> {
readonly size: number;
add(obj: T): Promise<boolean>;
contains(obj: T): Promise<boolean>;
remove(obj: T): Promise<boolean>;
clear(): Promise<void>;
clear(): void;
}
class NativeAsyncEqualitySet<T> implements AsyncEqualitySet<T> {
@@ -135,12 +134,12 @@ class NativeAsyncEqualitySet<T> implements AsyncEqualitySet<T> {
return this.#set.delete(obj);
}
async clear() {
clear() {
this.#set.clear();
}
[Symbol.asyncIterator]() {
return asAsyncGenerator(this.#set[Symbol.iterator]());
[Symbol.iterator]() {
return this.#set[Symbol.iterator]();
}
}
@@ -189,12 +188,12 @@ class CustomAsyncEqualitySet<T> implements AsyncEqualitySet<T> {
return false;
}
async clear() {
clear() {
this.#list.length = 0;
}
[Symbol.asyncIterator]() {
return asAsyncGenerator(this.#list[Symbol.iterator]());
[Symbol.iterator]() {
return this.#list[Symbol.iterator]();
}
}