env.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include "sleep.h"
  3. #include "spawn.h"
  4. #include <library/cpp/messagebus/actor/executor.h>
  5. #include <util/generic/ptr.h>
  6. namespace NRainCheck {
  7. struct IEnv {
  8. virtual ::NActor::TExecutor* GetExecutor() = 0;
  9. virtual ~IEnv() {
  10. }
  11. };
  12. template <typename TSelf>
  13. struct TEnvTemplate: public IEnv {
  14. template <typename TTask, typename TParam>
  15. TIntrusivePtr<typename TTask::TTaskRunner> SpawnTask(TParam param) {
  16. return ::NRainCheck::SpawnTask<TTask, TSelf>((TSelf*)this, param);
  17. }
  18. };
  19. template <typename TSelf>
  20. struct TSimpleEnvTemplate: public TEnvTemplate<TSelf> {
  21. ::NActor::TExecutorPtr Executor;
  22. TSleepService SleepService;
  23. TSimpleEnvTemplate(unsigned threadCount = 0)
  24. : Executor(new ::NActor::TExecutor(threadCount != 0 ? threadCount : 4))
  25. {
  26. }
  27. ::NActor::TExecutor* GetExecutor() override {
  28. return Executor.Get();
  29. }
  30. };
  31. struct TSimpleEnv: public TSimpleEnvTemplate<TSimpleEnv> {
  32. TSimpleEnv(unsigned threadCount = 0)
  33. : TSimpleEnvTemplate<TSimpleEnv>(threadCount)
  34. {
  35. }
  36. };
  37. }