docs/.vitepress/theme/components/extrepo/iconQueue.ts

7575d6c61cbe0df6f88e38ba3b11ecd8471a5984
wotaku/docs/.vitepress/theme/components/extrepo/iconQueue.ts

26 lines · 611 bytes

 1const MAX_CONCURRENT_MOBILE = 6
 2const MAX_CONCURRENT_DESKTOP = 24
 3
 4function maxConcurrent(): number {
 5  if (typeof window === 'undefined') return MAX_CONCURRENT_DESKTOP
 6  return window.matchMedia('(max-width: 767px)').matches ? MAX_CONCURRENT_MOBILE : MAX_CONCURRENT_DESKTOP
 7}
 8
 9let active = 0
10const queue: (() => Promise<void>)[] = []
11
12function pump() {
13  while (active < maxConcurrent() && queue.length) {
14    const job = queue.shift()!
15    active++
16    job().finally(() => {
17      active--
18      pump()
19    })
20  }
21}
22
23export function scheduleIconLoad(load: () => Promise<void>) {
24  queue.push(load)
25  pump()
26}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form