diff --git a/moxygen/QueueCallback.h b/moxygen/QueueCallback.h new file mode 100644 index 0000000..3549006 --- /dev/null +++ b/moxygen/QueueCallback.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include + +namespace moxygen { + +class QueueCallback : public ObjectReceiverCallback { + public: + struct Object { + moxygen::ObjectHeader header; + moxygen::Payload payload; + }; + folly::coro::UnboundedQueue> queue; + + FlowControlState onObject(const ObjectHeader& objHeader, Payload payload) + override { + queue.enqueue(Object({objHeader, std::move(payload)})); + return FlowControlState::UNBLOCKED; + } + void onObjectStatus(const ObjectHeader& hdr) override { + queue.enqueue(Object({hdr, nullptr})); + } + void onEndOfStream() override { + queue.enqueue(folly::makeUnexpected(folly::unit)); + } + void onError(ResetStreamErrorCode) override { + queue.enqueue(folly::makeUnexpected(folly::unit)); + } + void onSubscribeDone(SubscribeDone) override { + queue.enqueue(folly::makeUnexpected(folly::unit)); + } +}; +} // namespace moxygen