shouldYield static method

bool shouldYield({
  1. int? customBudgetMs,
})

Checks whether the current time slice has exceeded frameBudgetMs or a higher-priority task is queued.

Call this inside long loops to decide whether to invoke yieldNow.

if (BloomScheduler.shouldYield()) {
  await BloomScheduler.yieldNow();
}

Implementation

static bool shouldYield({int? customBudgetMs}) {
  if (_host.isSynchronous) return false;
  final budget = customBudgetMs ?? frameBudgetMs;
  if (_sliceStopwatch.isRunning &&
      _sliceStopwatch.elapsedMilliseconds >= budget) {
    return true;
  }
  // Check if urgent work arrived while running low/idle tasks
  if (_queues[TaskPriority.immediate.indexValue].isNotEmpty ||
      _queues[TaskPriority.userBlocking.indexValue].isNotEmpty) {
    return true;
  }
  return false;
}