Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
ed6de444
Commit
ed6de444
authored
4 years ago
by
Bekerle, Patrizio
Committed by
Reiter, Christoph
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add async foreach functions
parent
6e997ab6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/common/utils.js
+47
-1
47 additions, 1 deletion
packages/common/utils.js
with
47 additions
and
1 deletion
packages/common/utils.js
+
47
−
1
View file @
ed6de444
...
@@ -248,7 +248,7 @@ export const getAssetURL = (path) => {
...
@@ -248,7 +248,7 @@ export const getAssetURL = (path) => {
* @param timeout
* @param timeout
* @param interval
* @param interval
*/
*/
export
const
pollFunc
=
(
fn
,
timeout
,
interval
)
=>
{
export
const
pollFunc
=
(
fn
,
timeout
,
interval
)
=>
{
var
startTime
=
(
new
Date
()).
getTime
();
var
startTime
=
(
new
Date
()).
getTime
();
interval
=
interval
||
1000
;
interval
=
interval
||
1000
;
...
@@ -264,3 +264,49 @@ export const pollFunc = (fn, timeout, interval) => {
...
@@ -264,3 +264,49 @@ export const pollFunc = (fn, timeout, interval) => {
}
}
})();
})();
};
};
/**
* Doing a async foreach for non-linear integer keys
*
* @param array
* @param callback
* @returns {Promise<void>}
*/
export
async
function
asyncObjectForEach
(
array
,
callback
)
{
const
keys
=
Object
.
keys
(
array
);
for
(
let
index
=
0
;
index
<
keys
.
length
;
index
++
)
{
const
key
=
keys
[
index
];
await
callback
(
array
[
key
],
key
,
array
);
}
}
/**
* Doing a async foreach for non-linear integer keys with a copy of the array
*
* @param array
* @param callback
* @returns {Promise<void>}
*/
export
async
function
asyncCopyObjectForEach
(
array
,
callback
)
{
const
arrayCopy
=
{...
array
};
const
keys
=
Object
.
keys
(
arrayCopy
);
for
(
let
index
=
0
;
index
<
keys
.
length
;
index
++
)
{
const
key
=
keys
[
index
];
await
callback
(
arrayCopy
[
key
],
key
,
arrayCopy
);
}
}
/**
* Doing a async foreach for linear integer keys
*
* @param array
* @param callback
* @returns {Promise<void>}
*/
export
async
function
asyncArrayForEach
(
array
,
callback
)
{
for
(
let
index
=
0
;
index
<
array
.
length
;
index
++
)
{
await
callback
(
array
[
index
],
index
,
array
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment