• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

haraka / Haraka / 26860023436

03 Jun 2026 02:27AM UTC coverage: 72.488% (-0.006%) from 72.494%
26860023436

push

github

web-flow
dep(eslint): update @haraka/eslint-config to v3, fix surfaced warnings (#3586)

1721 of 2268 branches covered (75.88%)

33 of 45 new or added lines in 15 files covered. (73.33%)

19 existing lines in 3 files now uncovered.

7807 of 10770 relevant lines covered (72.49%)

25.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.86
/outbound/timer_queue.js
1
'use strict'
9 ✔
2

9 ✔
3
const logger = require('../logger')
9 ✔
4

9 ✔
5
class TQTimer {
9 ✔
6
    constructor(id, fire_time, cb) {
9 ✔
7
        this.id = id
11 ✔
8
        this.fire_time = fire_time
11 ✔
9
        this.cb = cb
11 ✔
10
    }
11 ✔
11

9 ✔
12
    cancel() {
9 ✔
13
        this.cb = null
2 ✔
14
    }
2 ✔
15
}
9 ✔
16

9 ✔
17
class TimerQueue {
9 ✔
18
    constructor(interval = 1000) {
9 ✔
19
        this.name = 'outbound/timer_queue'
15 ✔
20
        this.queue = []
15 ✔
21
        this.interval_timer = setInterval(() => {
15 ✔
22
            this.fire()
19 ✔
23
        }, interval)
15 ✔
24
        this.interval_timer.unref() // allow server to exit
15 ✔
25
    }
15 ✔
26

9 ✔
27
    add(id, ms, cb) {
9 ✔
28
        const fire_time = Date.now() + ms
11 ✔
29

11 ✔
30
        const timer = new TQTimer(id, fire_time, cb)
11 ✔
31

11 ✔
32
        if (this.queue.length === 0 || fire_time >= this.queue[this.queue.length - 1].fire_time) {
11 ✔
33
            this.queue.push(timer)
4 ✔
34
            return timer
4 ✔
35
        }
4 ✔
36

1 ✔
37
        for (let i = 0; i < this.queue.length; i++) {
1 ✔
38
            if (this.queue[i].fire_time > fire_time) {
1 ✔
39
                this.queue.splice(i, 0, timer)
1 ✔
40
                return timer
1 ✔
41
            }
1 ✔
42
        }
1 !
43

×
44
        throw 'Should never get here'
×
45
    }
11 ✔
46

9 ✔
47
    discard(id) {
9 ✔
48
        for (let i = 0; i < this.queue.length; i++) {
2 ✔
49
            if (this.queue[i].id === id) {
2 ✔
50
                this.queue[i].cancel()
1 ✔
51
                return this.queue.splice(i, 1)
1 ✔
52
            }
1 ✔
53
        }
2 !
54

×
55
        throw `${id} not found`
×
56
    }
2 ✔
57

9 ✔
58
    fire() {
9 ✔
59
        if (this.queue.length === 0) return
19 ✔
60

19 ✔
61
        const now = Date.now()
19 ✔
62

19 ✔
63
        while (this.queue.length && this.queue[0].fire_time <= now) {
19 !
UNCOV
64
            const to_run = this.queue.shift()
×
UNCOV
65
            if (to_run.cb) to_run.cb()
×
UNCOV
66
        }
×
67
    }
19 ✔
68

9 ✔
69
    length() {
9 ✔
70
        return this.queue.length
11 ✔
71
    }
11 ✔
72

9 ✔
73
    drain() {
9 ✔
74
        logger.debug(this, `Draining ${this.queue.length} items from the queue`)
1 ✔
75
        while (this.queue.length) {
1 ✔
76
            const to_run = this.queue.shift()
2 ✔
77
            if (to_run.cb) to_run.cb()
2 !
78
        }
2 ✔
79
    }
1 ✔
80

9 ✔
81
    shutdown() {
9 ✔
82
        clearInterval(this.interval_timer)
4 ✔
83
    }
4 ✔
84
}
9 ✔
85

9 ✔
86
module.exports = TimerQueue
9 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc