A Bluesky labeler that labels accounts hosted on PDSes operated by entities other than Bluesky PBC
at main 990 B view raw
1import { priorityQueue, type AsyncPriorityQueue } from 'async'; 2 3export class TaskProcessor { 4 private maxParallelTasks: number; 5 private taskQueue: AsyncPriorityQueue<() => Promise<void>>; 6 7 constructor(maxParallelTasks: number) { 8 this.maxParallelTasks = maxParallelTasks; 9 this.taskQueue = priorityQueue(function (task, callback) { 10 task().then(() => callback(), (e) => callback(e)); 11 }, this.maxParallelTasks); 12 this.taskQueue.error((e) => { 13 console.log("Error in task queue task: " + e); 14 }) 15 console.log(`Task processor created with a maximum of ${maxParallelTasks} parallel tasks`); 16 } 17 18 schedule(task: () => Promise<any>, priority = 100): Promise<void> { 19 return new Promise((resolve) => { 20 this.taskQueue.buffer 21 this.taskQueue.push(task, priority, () => resolve()); 22 }) 23 } 24 25 unsaturated(): Promise<void> { 26 return this.taskQueue.unsaturated(); 27 } 28}