First upload version 0.0.1
This commit is contained in:
29
node_modules/node-llama-cpp/dist/bindings/utils/asyncSome.js
generated
vendored
Normal file
29
node_modules/node-llama-cpp/dist/bindings/utils/asyncSome.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getConsoleLogPrefix } from "../../utils/getConsoleLogPrefix.js";
|
||||
/**
|
||||
* Returns a promise that fulfills as soon as any of the promises return `true`.
|
||||
* Note that this function will not throw on error and instead will log the error to the console.
|
||||
*/
|
||||
export async function asyncSome(promises) {
|
||||
if (promises.length === 0)
|
||||
return Promise.resolve(false);
|
||||
return new Promise((resolve) => {
|
||||
let fulfilled = 0;
|
||||
for (const promise of promises) {
|
||||
promise
|
||||
.then((result) => {
|
||||
if (result)
|
||||
return void resolve(true);
|
||||
fulfilled++;
|
||||
if (fulfilled === promises.length)
|
||||
resolve(false);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(getConsoleLogPrefix(false, false), err);
|
||||
fulfilled++;
|
||||
if (fulfilled === promises.length)
|
||||
resolve(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=asyncSome.js.map
|
||||
Reference in New Issue
Block a user