aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcorespi/flush/lambdaflushtask.h
blob: 75737ce73d51688ebf1abbe3e01fbf2046b8c9de (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "flushtask.h"

namespace searchcorespi {

template <class FunctionType>
class LambdaFlushTask : public FlushTask {
    FunctionType _func;
    search::SerialNum _flushSerial;

public:
    LambdaFlushTask(FunctionType &&func, search::SerialNum flushSerial)
        : _func(std::move(func)),
          _flushSerial(flushSerial)
    {}
    ~LambdaFlushTask() override = default;
    search::SerialNum getFlushSerial() const override { return _flushSerial; }
    void run() override { _func(); }
};

template <class FunctionType>
std::unique_ptr<FlushTask>
makeLambdaFlushTask(FunctionType &&function, search::SerialNum flushSerial)
{
    return std::make_unique<LambdaFlushTask<std::decay_t<FunctionType>>>
            (std::forward<FunctionType>(function), flushSerial);
}

}