import { QueueScheduler } from './queue-scheduler.js' ; import { TaskContext } from './task-context.js' ; import { Task } from './task.js' ; export class TaskQueue { readonly tasks = new Set < TaskContext < any > > ( ) ; readonly scheduler : QueueScheduler ; constructor ( scheduler ) { this . scheduler = scheduler ; } scheduleTask < T > ( task ) { const context = new TaskContext ( task ) ; this . tasks . add ( context ) ; this . scheduler . schedule ( this ) ; return context . completed ; } removeTask ( task ) { console . assert ( this . tasks . has ( task ) ) ; this . tasks . delete ( task ) ; } }