Add task queue, work on socket

This commit is contained in:
Jon Staab
2025-03-20 14:22:40 -07:00
parent 7706034b99
commit 7d0d303dae
10 changed files with 345 additions and 35 deletions
+18
View File
@@ -351,6 +351,24 @@ export const displayDomain = (url: string) => displayUrl(first(url.split(/[\/\?]
*/
export const sleep = (t: number) => new Promise(resolve => setTimeout(resolve, t))
/**
* Creates a microtask that yields to other tasks in the event loop
* @returns Promise that resolves after yielding
*/
export const yieldThread = () => {
if (
typeof window !== "undefined" &&
"scheduler" in window &&
"yield" in (window as any).scheduler
) {
return (window as any).scheduler.yield()
}
return new Promise<void>(resolve => {
setTimeout(resolve, 0)
})
}
/**
* Concatenates multiple arrays, filtering out null/undefined
* @param xs - Arrays to concatenate