blob: f6dd7fceb62a37a56a1a0dddb73101aa14cded33 (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  | 
#pragma once
#include "sleep.h"
#include "spawn.h"
#include <library/cpp/messagebus/actor/executor.h>
#include <util/generic/ptr.h>
namespace NRainCheck {
    struct IEnv {
        virtual ::NActor::TExecutor* GetExecutor() = 0;
        virtual ~IEnv() {
        }
    };
    template <typename TSelf>
    struct TEnvTemplate: public IEnv {
        template <typename TTask, typename TParam>
        TIntrusivePtr<typename TTask::TTaskRunner> SpawnTask(TParam param) {
            return ::NRainCheck::SpawnTask<TTask, TSelf>((TSelf*)this, param);
        }
    };
    template <typename TSelf>
    struct TSimpleEnvTemplate: public TEnvTemplate<TSelf> {
        ::NActor::TExecutorPtr Executor;
        TSleepService SleepService;
        TSimpleEnvTemplate(unsigned threadCount = 0)
            : Executor(new ::NActor::TExecutor(threadCount != 0 ? threadCount : 4))
        {
        }
        ::NActor::TExecutor* GetExecutor() override {
            return Executor.Get();
        }
    };
    struct TSimpleEnv: public TSimpleEnvTemplate<TSimpleEnv> {
        TSimpleEnv(unsigned threadCount = 0)
            : TSimpleEnvTemplate<TSimpleEnv>(threadCount)
        {
        }
    };
}
  |