Skip to content

Commit

Permalink
♻️ inline previous promiseEscape() util
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Feb 12, 2024
1 parent 447e4a2 commit 137eec7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 42 deletions.
3 changes: 2 additions & 1 deletion playground/playground.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isTimeToYield, SchedulingStrategy, withResolvers, yieldOrContinue } from '../index'
import { isTimeToYield, SchedulingStrategy, yieldOrContinue } from '../index'
import simulateWork from './utils/simulateWork'
import waitNextTask from '../src/utils/waitNextTask'
import withResolvers from '../src/utils/withResolvers'

document.querySelector('#run-interactive')!.addEventListener('click', () => {
run('interactive')
Expand Down
15 changes: 11 additions & 4 deletions src/ThreadScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ScheduledTask from './ScheduledTask'
import WorkCycleTracker from './WorkCycleTracker'
import SchedulingStrategy from './SchedulingStrategy'
import withResolvers from './utils/withResolvers'
import { requestPromiseEscape } from './utils/promiseEscape'
import ReactiveTask from './utils/ReactiveTask'

const strategyPriorities = {
Expand Down Expand Up @@ -51,9 +50,17 @@ class ThreadScheduler {

task.resolve()

// wait for the user code to continue running the code to see if he will add more work to
// be done. we prefer this, other than continuing to the next task immediately
await new Promise<void>((resolve) => requestPromiseEscape(resolve))
// - wait for the user code to continue running to see if it will add more work to
// be done. we prefer this, over continuing to the next task immediately
// - if called at the end of an async method, it will wait for the async to get resolved in the
// parent method that called it and will execute the provided callback in the next microtask.
await new Promise<void>((resolve) => {
queueMicrotask(() => {
queueMicrotask(() => {
resolve()
})
})
})

this.#removeTask(task)
}
Expand Down
37 changes: 0 additions & 37 deletions src/utils/promiseEscape.ts

This file was deleted.

0 comments on commit 137eec7

Please sign in to comment.