Skip to content

Commit d1aa77e

Browse files
committed
feat(asyncEmptyOnce): add asyncEmptyOnce function
1 parent 3305846 commit d1aa77e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

index.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {ExecutionContext} from "ava";
22
import test from "ava";
33
import {
4+
asyncEmptyOnce,
45
asyncInitialOnce,
56
asyncIterator,
67
asyncLastOnce,
@@ -132,3 +133,9 @@ test("asyncOnlyOnce", async t => {
132133
t.is(await asyncOnlyOnce(asyncIterator([4])), 4);
133134
t.is(await asyncOnlyOnce(asyncIterator([3, 4, 5])), null);
134135
});
136+
137+
test("asyncEmptyOnce", async t => {
138+
t.is(await asyncEmptyOnce(asyncIterator([])), true);
139+
t.is(await asyncEmptyOnce(asyncIterator([1])), false);
140+
t.is(await asyncEmptyOnce(asyncIterator([1, 2, 3])), false);
141+
});

index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,7 @@ export async function asyncOnlyOnce<T>(iterator: AsyncIteratorLike<T>): Promise<
186186
return null;
187187
}
188188
}
189+
190+
export async function asyncEmptyOnce<T>(iterator: AsyncIteratorLike<T>): Promise<boolean> {
191+
return (await asyncIterator(iterator).next()).done === true;
192+
}

0 commit comments

Comments
 (0)