jobqueue.h 809 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <library/cpp/coroutine/engine/impl.h>
  3. #include <util/generic/yexception.h>
  4. #include <util/stream/output.h>
  5. namespace NNeh {
  6. class IJob {
  7. public:
  8. inline void operator()(TCont* c) noexcept {
  9. try {
  10. DoRun(c);
  11. } catch (...) {
  12. Cdbg << "run " << CurrentExceptionMessage() << Endl;
  13. }
  14. }
  15. virtual ~IJob() {
  16. }
  17. private:
  18. virtual void DoRun(TCont* c) = 0;
  19. };
  20. class IJobQueue {
  21. public:
  22. template <class T>
  23. inline void Schedule(T req) {
  24. ScheduleImpl(req.Get());
  25. Y_UNUSED(req.Release());
  26. }
  27. virtual void ScheduleImpl(IJob* job) = 0;
  28. virtual ~IJobQueue() {
  29. }
  30. };
  31. IJobQueue* JobQueue();
  32. }