import { PreparedOp, Task } from '../../types';

const awaitedTasks: Task[] = [];

export const pushAwaitedTask = (op: PreparedOp) => {
  awaitedTasks.push({ op, batchId: -1 });
};

export const getAwaitedTasks = () => [...awaitedTasks];

export const markTaskBatch = (count: number, batchId: number) => {
  for (let i = 1; i <= count; i++) {
    awaitedTasks.at(i * -1)!.batchId = batchId;
  }
};

export const getAwaitedTasksCount = () => awaitedTasks.length;
