summaryrefslogtreecommitdiff
path: root/app/relay/queue.js
blob: d6e7ffe4cc25bc118da552c7c8d0ae355b010d14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// get the processor that uses the task and give it its own queue!

export class Queue {
  constructor(processor){
    this.a = []
    this.processor = processor
    this.active = false
    this.status = 'waiting'
  }
  is_active() {
    if (this.active && this.a.length) {
      return true
    }
    this.status = 'waiting'
    this.active = false
    return false
  }
  get_status() {
    return this.status
  }
  activate() {
    this.active = true
    this.status = 'active'
  }
  deactivate(reason) {
    this.active = false
    this.status = reason || 'waiting'
  }
  add_task(task){
    this.a.push(task)
  }
  remove_task(task){
    this.a = this.a.filter(t => t.id !== task.id)
  }
  get_next_task(){
    return this.a.shift()
  }
  list_tasks(){
    return this.a
  }
}


export const cpu = new Queue('cpu')
export const gpu = new Queue('gpu')