Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Immediate queue management #16120

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions packages/dev/core/src/Misc/timingTools.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { IsWindowObjectExist } from "./domManagement";
let _immediateQueue: Array<() => void> = [];

/**
* Class used to provide helper for timing
*/
export class TimingTools {
/**
* Polyfill for setImmediate
* Execute a function after the current execution block
* @param action defines the action to execute after the current execution block
*/
public static SetImmediate(action: () => void) {
if (IsWindowObjectExist() && window.setImmediate) {
// Note - deprecated and should not be used directly. Not supported in any browser.
window.setImmediate(action);
} else {
setTimeout(action, 1);
if (_immediateQueue.length === 0) {
setTimeout(() => {
// Execute all immediate functions
const functionsToCall = _immediateQueue;
_immediateQueue = [];

for (const func of functionsToCall) {
func();
}
}, 1);
}
_immediateQueue.push(action);
}
}

Expand Down