Coverage Report

Created: 2026-02-16 07:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/AK/GenericAwaiter.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Ali Mohammad Pur <mpfard@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Coroutine.h>
10
#include <AK/Error.h>
11
#include <AK/Function.h>
12
13
namespace AK {
14
class GenericAwaiter {
15
    AK_MAKE_NONMOVABLE(GenericAwaiter);
16
    AK_MAKE_NONCOPYABLE(GenericAwaiter);
17
18
public:
19
    GenericAwaiter(Function<void(Function<void()>)>&& fn)
20
0
    {
21
0
        fn([this] { ready(); });
22
0
    }
23
24
0
    bool await_ready() const { return false; }
25
    void await_suspend(std::coroutine_handle<> handle)
26
0
    {
27
0
        m_handle = handle;
28
0
    }
29
    ErrorOr<void> await_resume()
30
0
    {
31
0
        m_handle = {};
32
0
        return {};
33
0
    }
34
35
private:
36
    void ready()
37
0
    {
38
0
        if (m_handle)
39
0
            m_handle.resume();
40
0
    }
41
42
    std::coroutine_handle<> m_handle;
43
};
44
}
45
46
#ifdef USING_AK_GLOBALLY
47
using AK::GenericAwaiter;
48
#endif