Skip to content

Commit 815a29d

Browse files
afrindfacebook-github-bot
authored andcommitted
ObjectReceiver callback that inserts objects into a queue
Summary: This is an adapter that is close to the old MoQSession read interface. Reviewed By: sharmafb Differential Revision: D67245323 fbshipit-source-id: 5eff879d005e2883f95250e3f3aa73777d99efbf
1 parent e7fad1b commit 815a29d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

moxygen/QueueCallback.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#include <folly/coro/UnboundedQueue.h>
4+
#include <moxygen/ObjectReceiver.h>
5+
6+
namespace moxygen {
7+
8+
class QueueCallback : public ObjectReceiverCallback {
9+
public:
10+
struct Object {
11+
moxygen::ObjectHeader header;
12+
moxygen::Payload payload;
13+
};
14+
folly::coro::UnboundedQueue<folly::Expected<Object, folly::Unit>> queue;
15+
16+
FlowControlState onObject(const ObjectHeader& objHeader, Payload payload)
17+
override {
18+
queue.enqueue(Object({objHeader, std::move(payload)}));
19+
return FlowControlState::UNBLOCKED;
20+
}
21+
void onObjectStatus(const ObjectHeader& hdr) override {
22+
queue.enqueue(Object({hdr, nullptr}));
23+
}
24+
void onEndOfStream() override {
25+
queue.enqueue(folly::makeUnexpected(folly::unit));
26+
}
27+
void onError(ResetStreamErrorCode) override {
28+
queue.enqueue(folly::makeUnexpected(folly::unit));
29+
}
30+
void onSubscribeDone(SubscribeDone) override {
31+
queue.enqueue(folly::makeUnexpected(folly::unit));
32+
}
33+
};
34+
} // namespace moxygen

0 commit comments

Comments
 (0)