Skip to content
Snippets Groups Projects
Commit cd4eec11 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Add function pollFunc

parent 043828de
No related branches found
No related tags found
No related merge requests found
...@@ -225,4 +225,28 @@ export const getAssetURL = (path) => { ...@@ -225,4 +225,28 @@ export const getAssetURL = (path) => {
// If all fails we just fall back to relative paths and hope the // If all fails we just fall back to relative paths and hope the
// html is on the same path as the bundle // html is on the same path as the bundle
return path; return path;
}; };
\ No newline at end of file
/**
* Poll <fn> every <interval> ms until <timeout> ms
*
* @param fn
* @param timeout
* @param interval
*/
export const pollFunc = (fn, timeout, interval) => {
var startTime = (new Date()).getTime();
interval = interval || 1000;
(function p() {
// don't retry if we took longer than timeout ms
if (((new Date).getTime() - startTime ) > timeout) {
return;
}
// retry until fn() returns true
if (!fn()) {
setTimeout(p, interval);
}
})();
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment