Skip to content

Commit

Permalink
ObjectReceiver callback that inserts objects into a queue
Browse files Browse the repository at this point in the history
Summary: This is an adapter that is close to the old MoQSession read interface.

Reviewed By: sharmafb

Differential Revision: D67245323

fbshipit-source-id: 5eff879d005e2883f95250e3f3aa73777d99efbf
  • Loading branch information
afrind authored and facebook-github-bot committed Dec 16, 2024
1 parent e7fad1b commit 815a29d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions moxygen/QueueCallback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <folly/coro/UnboundedQueue.h>
#include <moxygen/ObjectReceiver.h>

namespace moxygen {

class QueueCallback : public ObjectReceiverCallback {
public:
struct Object {
moxygen::ObjectHeader header;
moxygen::Payload payload;
};
folly::coro::UnboundedQueue<folly::Expected<Object, folly::Unit>> 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

0 comments on commit 815a29d

Please sign in to comment.