MCPcopy Create free account
hub / github.com/microsoft/vscode-cpptools / asyncOf

Function asyncOf

Extension/src/Utility/Async/iterators.ts:139–161  ·  view source on GitHub ↗
(...items: (undefined | Promise<undefined> | Some<T>)[])

Source from the content-addressed store, hash-verified

137export type Some<T> = T | Promise<T> | AsyncIterable<T | undefined> | AsyncIterable<Promise<T> | Promise<undefined>> | Iterable<T> | Iterable<Promise<T>>;
138
139export async function* asyncOf<T>(...items: (undefined | Promise<undefined> | Some<T>)[]): AsyncIterable<NonNullable<T>> {
140 if (is.asyncIterable(items)) {
141 for await (const item of items) {
142 if (is.asyncIterable(item) || is.iterable(item)) {
143 yield* item as any;
144 continue;
145 }
146 yield item as any;
147 }
148 return;
149 }
150
151 for (const item of items) {
152 // skip undefined
153 if (item) {
154 if (is.asyncIterable(item) || is.iterable(item)) {
155 yield* item as any;
156 continue;
157 }
158 yield item as any;
159 }
160 }
161}
162
163/**
164 * A substitute for Promise.race()

Callers 2

accumulatorFunction · 0.85
combinerFunction · 0.85

Calls 2

asyncIterableMethod · 0.80
iterableMethod · 0.80

Tested by

no test coverage detected