MCPcopy Create free account
hub / github.com/code-pushup/cli / wrapWithDefer

Function wrapWithDefer

packages/utils/perf/crawl-file-system/index.ts:85–103  ·  view source on GitHub ↗
(
  asyncFn: (options: CrawlFileSystemOptions<T>) => Promise<unknown[]>,
)

Source from the content-addressed store, hash-verified

83// ==============================================================
84
85function wrapWithDefer<T>(
86 asyncFn: (options: CrawlFileSystemOptions<T>) => Promise<unknown[]>,
87) {
88 return {
89 defer: true, // important for async functions
90 fn(deferred: { resolve: () => void }) {
91 return asyncFn(options)
92 .catch(() => [])
93 .then((result: unknown[]) => {
94 if (result.length === 0) {
95 throw new Error(`Result length is ${result.length}`);
96 } else {
97 deferred.resolve();
98 }
99 return void 0;
100 });
101 },
102 };
103}

Callers 1

index.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected