@shgysk8zer0/polyfills 0.4.9 → 0.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,15 +45,19 @@ function getTaskCallback(callback, resolve, reject, signal) {
45
45
 
46
46
  export class Scheduler {
47
47
  async postTask(callback, {
48
- priority = PRIORITIES.visible,
48
+ priority,
49
49
  delay,
50
50
  signal,
51
51
  } = {}) {
52
52
  const { promise, resolve, reject } = Promise.withResolvers();
53
53
  const controller = new AbortController();
54
- const hasDelay = Number.isSafeInteger(delay) && delay >= 0;
54
+ const hasDelay = Number.isSafeInteger(delay) && delay > -1;
55
55
  const taskCallback = getTaskCallback(callback, resolve, reject, signal);
56
56
 
57
+ if (typeof priority === 'undefined') {
58
+ priority = signal instanceof globalThis.TaskSignal ? signal.priority : PRIORITIES.visible;
59
+ }
60
+
57
61
  if (signal instanceof AbortSignal && signal.aborted) {
58
62
  reject(signal.reason);
59
63
  } else {
@@ -116,22 +120,7 @@ export class Scheduler {
116
120
  });
117
121
  }
118
122
 
119
- async yield({ signal, priority = PRIORITIES.blocking } = {}) {
120
- switch(priority) {
121
- case PRIORITIES.visible:
122
- await this.postTask(() => {}, { signal, priority: PRIORITIES.visible });
123
- break;
124
-
125
- case PRIORITIES.blocking:
126
- await this.postTask(() => {}, { signal, priority: PRIORITIES.blocking, delay: 0 });
127
- break;
128
-
129
- case PRIORITIES.background:
130
- await this.postTask(() => {}, { signal, priority: PRIORITIES.background });
131
- break;
132
-
133
- default:
134
- throw new TypeError(`Scheduler.yield: '${priority}' (value of 'priority' member of SchedulerPostTaskOptions) is not a valid value for enumeration TaskPriority.`);
135
- }
123
+ async yield() {
124
+ await this.postTask(() => null, { priority: PRIORITIES.visible });
136
125
  }
137
126
  }