Perf: enhance forEach method in Util class to handle asynchronous handlers

This commit is contained in:
Cell
2025-08-12 17:48:52 +08:00
parent 45f101a456
commit b27a3098ac
2 changed files with 7 additions and 2 deletions
+6 -1
View File
@@ -1,9 +1,14 @@
export default class Util {
forEach(elements, handler) {
elements = elements || [];
const promises = [];
for (let i = 0; i < elements.length; i++) {
handler(elements[i]);
const result = handler(elements[i], i);
if (result instanceof Promise) {
promises.push(result);
}
}
return Promise.all(promises);
}
getScrollTop() {
+1 -1
View File
@@ -1,4 +1,4 @@
{{- hugo.Store.Set "version" "v0.4.0-alpha-20250812032013-fe351c7e" -}}
{{- hugo.Store.Set "version" "v0.4.0-alpha-20250812094854-45f101a4" -}}
{{- .Store.Set "this" dict -}}
{{- partial "init/detection-env.html" . -}}