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

haraka / Haraka / 26427888890

26 May 2026 01:56AM UTC coverage: 73.353% (-0.3%) from 73.64%
26427888890

Pull #3577

github

web-flow
Merge d6883ed79 into c4173efb8
Pull Request #3577: Implicit TLS with Proxy Protocol

1807 of 2349 branches covered (76.93%)

186 of 220 new or added lines in 2 files covered. (84.55%)

93 existing lines in 7 files now uncovered.

8115 of 11063 relevant lines covered (73.35%)

24.4 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()
16✔
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)
10✔
34
            return timer
10✔
35
        }
10✔
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) {
3✔
50
                this.queue[i].cancel()
2✔
51
                return this.queue.splice(i, 1)
2✔
52
            }
2✔
53
        }
3✔
54

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

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

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

9✔
63
        while (this.queue.length && this.queue[0].fire_time <= now) {
16!
UNCOV
64
            const to_run = this.queue.shift()
×
UNCOV
65
            if (to_run.cb) to_run.cb()
×
UNCOV
66
        }
×
67
    }
16✔
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 · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc