aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/lambdatask.h
blob: 070b06f31b51693cef84abd9901d8175356c9d9c (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "executor.h"

namespace vespalib {

template <class FunctionType>
class LambdaTask : public vespalib::Executor::Task {
    FunctionType _func;

public:
    LambdaTask(const FunctionType &func) : _func(func) {}
    LambdaTask(FunctionType &&func) : _func(std::move(func)) {}
    LambdaTask(const LambdaTask &) = delete;
    LambdaTask & operator = (const LambdaTask &) = delete;
    ~LambdaTask() {}
    void run() override { _func(); }
};

template <class FunctionType>
vespalib::Executor::Task::UP
makeLambdaTask(FunctionType &&function)
{
    return std::make_unique<LambdaTask<std::decay_t<FunctionType>>>
        (std::forward<FunctionType>(function));
}

}