Skip to content

Commit

Permalink
♻️ scheduler → threadScheduler (don't use the browser name)
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Feb 5, 2024
1 parent 91502d5 commit cc4a77f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions playground/playground.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isTimeToYield, SchedulingStrategy, withResolvers, yieldOrContinue } from '../index'
import scheduler from '../src/Scheduler'
import { isTimeToYield, SchedulingStrategy, yieldOrContinue } from '../index'
import threadScheduler from '../src/ThreadScheduler'

document.querySelector('#run-interactive')!.addEventListener('click', () => {
run('interactive')
Expand Down Expand Up @@ -55,7 +55,7 @@ async function runPostTask(priority: 'user-blocking' | 'user-visible' | 'backgro
const iterations = Math.round(totalTime / singleTaskTime)
for (let i = 0; i < iterations; i++) {
// @ts-ignore
scheduler.postTask(
threadScheduler.postTask(
() => {
const start = Date.now()
while (Date.now() - start < singleTaskTime) {}
Expand Down
6 changes: 3 additions & 3 deletions src/Scheduler.ts → src/ThreadScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const strategyPriorities = {
idle: 10,
}

class Scheduler {
class ThreadScheduler {
#tasks: ScheduledTask[] = []
#topTask: ReactiveTask = new ReactiveTask()
#workCycleTracker = new WorkCycleTracker()
Expand Down Expand Up @@ -82,6 +82,6 @@ class Scheduler {
}
}

const scheduler = new Scheduler()
const threadScheduler = new ThreadScheduler()

export default scheduler
export default threadScheduler
4 changes: 2 additions & 2 deletions src/isTimeToYield.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hasValidContext from './utils/hasValidContext'
import SchedulingStrategy from './SchedulingStrategy'
import scheduler from './Scheduler'
import threadScheduler from './ThreadScheduler'

// #performance
// calling `isTimeToYield()` thousand of times is slow
Expand Down Expand Up @@ -33,7 +33,7 @@ export default function isTimeToYield(strategy: SchedulingStrategy = 'smooth'):
}

cache.lastCallTime = now
cache.lastResult = scheduler.isTimeToYield(strategy)
cache.lastResult = threadScheduler.isTimeToYield(strategy)

return cache.lastResult
}
4 changes: 2 additions & 2 deletions src/yieldControl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hasValidContext from './utils/hasValidContext'
import SchedulingStrategy from './SchedulingStrategy'
import scheduler from './Scheduler'
import threadScheduler from './ThreadScheduler'

/**
* Waits for the browser to become idle again in order to resume work. Calling `yieldControl()`
Expand All @@ -17,6 +17,6 @@ export default async function yieldControl(strategy: SchedulingStrategy = 'smoot
return
}

const task = scheduler.createTask(strategy)
const task = threadScheduler.createTask(strategy)
return task.promise
}

0 comments on commit cc4a77f

Please sign in to comment.