Skip to content

Commit c68f349

Browse files
committed
feat(asyncFirstOnce): add asyncFirstOnce function
1 parent 2a7c28d commit c68f349

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,13 @@ export async function asyncToSetOnce<T>(iterator: AsyncIteratorLike<T>): Promise
8686
}
8787
return set;
8888
}
89+
90+
export async function asyncFirstOnce<T>(iterator: AsyncIteratorLike<T>): Promise<T | null> {
91+
const it = asyncIterator(iterator);
92+
const element = await it.next();
93+
if (element.done === true) {
94+
return null;
95+
} else {
96+
return element.value;
97+
}
98+
}

0 commit comments

Comments
 (0)