@graphql-mesh/utils
Version:
25 lines (24 loc) • 703 B
JavaScript
import { isPromise } from '@graphql-tools/utils';
export function iterateAsync(iterable, callback, results) {
const iterator = iterable[Symbol.iterator]();
function iterate() {
const { done: endOfIterator, value } = iterator.next();
if (endOfIterator) {
return;
}
const result$ = callback(value);
if (isPromise(result$)) {
return result$.then(result => {
if (result) {
results?.push(result);
}
return iterate();
});
}
if (result$) {
results?.push(result$);
}
return iterate();
}
return iterate();
}