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

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

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

95.24
/src/base/future_util.hh
1
/**
2
 * Copyright (c) 2020, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#ifndef lnav_future_util_hh
31
#define lnav_future_util_hh
32

33
#include <deque>
34
#include <future>
35

36
#include "progress.hh"
37

38
namespace lnav::futures {
39

40
/**
41
 * Create a future that is ready to immediately return a result.
42
 *
43
 * @tparam T The result type of the future.
44
 * @param t The value the future should return.
45
 * @return The new future.
46
 */
47
template<class T>
48
std::future<std::decay_t<T>>
49
make_ready_future(T&& t)
2✔
50
{
51
    std::promise<std::decay_t<T>> pr;
2✔
52
    auto r = pr.get_future();
2✔
53
    pr.set_value(std::forward<T>(t));
2✔
54
    return r;
4✔
55
}
2✔
56

57
/**
58
 * A queue used to limit the number of futures that are running concurrently.
59
 *
60
 * @tparam T The result of the futures.
61
 */
62
template<typename T>
63
class future_queue {
64
public:
65
    /**
66
     * @param processor The function to execute with the result of a future.
67
     * @param max_queue_size The maximum number of futures that can be in
68
     * flight.
69
     */
70
    explicit future_queue(
2,719✔
71
        std::function<lnav::progress_result_t(std::future<T>&)> processor,
72
        size_t max_queue_size = 8)
73
        : fq_processor(std::move(processor)), fq_max_queue_size(max_queue_size)
2,719✔
74
    {
75
    }
2,719✔
76

77
    future_queue(const future_queue&) = delete;
78
    future_queue& operator=(const future_queue&) = delete;
79

80
    ~future_queue() { this->pop_to(); }
2,719✔
81

82
    /**
83
     * Add a future to the queue.  If the size of the queue is greater than the
84
     * MAX_QUEUE_SIZE, this call will block waiting for the first queued
85
     * future to return a result.
86
     *
87
     * @param f The future to add to the queue.
88
     */
89
    lnav::progress_result_t push_back(std::future<T>&& f)
577✔
90
    {
91
        this->fq_deque.emplace_back(std::move(f));
577✔
92
        return this->pop_to(this->fq_max_queue_size);
577✔
93
    }
94

95
    /**
96
     * Removes the next future from the queue, waits for the result, and then
97
     * repeats until the queue reaches the given size.
98
     *
99
     * @param size The new desired size of the queue.
100
     */
101
    lnav::progress_result_t pop_to(size_t size = 0)
6,015✔
102
    {
103
        lnav::progress_result_t retval = lnav::progress_result_t::ok;
6,015✔
104

105
        while (this->fq_deque.size() > size) {
6,592✔
106
            if (this->fq_processor(this->fq_deque.front())
577✔
107
                == lnav::progress_result_t::interrupt)
577✔
108
            {
UNCOV
109
                retval = lnav::progress_result_t::interrupt;
×
110
            }
111
            this->fq_deque.pop_front();
577✔
112
        }
113
        return retval;
6,015✔
114
    }
115

116
    std::function<lnav::progress_result_t(std::future<T>&)> fq_processor;
117
    std::deque<std::future<T>> fq_deque;
118
    size_t fq_max_queue_size;
119
};
120

121
}  // namespace lnav::futures
122

123
#endif
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