Commit b56cffe6 authored by Andrew Smith's avatar Andrew Smith Committed by Facebook GitHub Bot

Change Transform template parameter names

Summary: This diff changes Transform's parameter names to conform to folly's style guidelines.

Reviewed By: Gownta

Differential Revision: D33033366

fbshipit-source-id: 3713ec7995df3dd913f4da11d21fbd9377c1f00f
parent aa378653
...@@ -52,21 +52,21 @@ namespace detail { ...@@ -52,21 +52,21 @@ namespace detail {
* to CancellationProcessed (and the object is deleted). * to CancellationProcessed (and the object is deleted).
*/ */
template < template <
typename TInputValue, typename InputValueType,
typename TOutputValue, typename OutputValueType,
typename TransformValueFunc> typename TransformValueFunc>
class TransformProcessorBase : public IChannelCallback { class TransformProcessorBase : public IChannelCallback {
public: public:
TransformProcessorBase( TransformProcessorBase(
Sender<TOutputValue> sender, Sender<OutputValueType> sender,
folly::Executor::KeepAlive<folly::SequencedExecutor> executor, folly::Executor::KeepAlive<folly::SequencedExecutor> executor,
TransformValueFunc transformValue) TransformValueFunc transformValue)
: sender_(std::move(senderGetBridge(sender))), : sender_(std::move(senderGetBridge(sender))),
executor_(std::move(executor)), executor_(std::move(executor)),
transformValue_(std::move(transformValue)) {} transformValue_(std::move(transformValue)) {}
template <typename TReceiver> template <typename ReceiverType>
void startTransform(TReceiver receiver) { void startTransform(ReceiverType receiver) {
executor_->add([=, receiver = std::move(receiver)]() mutable { executor_->add([=, receiver = std::move(receiver)]() mutable {
runOperationWithSenderCancellation( runOperationWithSenderCancellation(
this->executor_, this->executor_,
...@@ -84,7 +84,8 @@ class TransformProcessorBase : public IChannelCallback { ...@@ -84,7 +84,8 @@ class TransformProcessorBase : public IChannelCallback {
* *
* @param inputReceiver: The input receiver to transform values from. * @param inputReceiver: The input receiver to transform values from.
*/ */
folly::coro::Task<void> startTransformImpl(Receiver<TInputValue> receiver) { folly::coro::Task<void> startTransformImpl(
Receiver<InputValueType> receiver) {
auto [unbufferedInputReceiver, buffer] = auto [unbufferedInputReceiver, buffer] =
detail::receiverUnbuffer(std::move(receiver)); detail::receiverUnbuffer(std::move(receiver));
receiver_ = std::move(unbufferedInputReceiver); receiver_ = std::move(unbufferedInputReceiver);
...@@ -148,7 +149,7 @@ class TransformProcessorBase : public IChannelCallback { ...@@ -148,7 +149,7 @@ class TransformProcessorBase : public IChannelCallback {
* will process cancellation for the input receiver. * will process cancellation for the input receiver.
*/ */
folly::coro::Task<void> processAllAvailableValues( folly::coro::Task<void> processAllAvailableValues(
std::optional<ReceiverQueue<TInputValue>> buffer = std::nullopt) { std::optional<ReceiverQueue<InputValueType>> buffer = std::nullopt) {
auto closeResult = buffer.has_value() auto closeResult = buffer.has_value()
? co_await processValues(std::move(buffer.value())) ? co_await processValues(std::move(buffer.value()))
: std::nullopt; : std::nullopt;
...@@ -180,14 +181,14 @@ class TransformProcessorBase : public IChannelCallback { ...@@ -180,14 +181,14 @@ class TransformProcessorBase : public IChannelCallback {
* used to close the output receiver. * used to close the output receiver.
*/ */
folly::coro::Task<std::optional<CloseResult>> processValues( folly::coro::Task<std::optional<CloseResult>> processValues(
ReceiverQueue<TInputValue> values) { ReceiverQueue<InputValueType> values) {
auto cancelToken = co_await folly::coro::co_current_cancellation_token; auto cancelToken = co_await folly::coro::co_current_cancellation_token;
while (!values.empty()) { while (!values.empty()) {
auto inputResult = std::move(values.front()); auto inputResult = std::move(values.front());
values.pop(); values.pop();
bool inputClosed = !inputResult.hasValue(); bool inputClosed = !inputResult.hasValue();
if (!inputResult.hasValue() && !inputResult.hasException()) { if (!inputResult.hasValue() && !inputResult.hasException()) {
inputResult = folly::Try<TInputValue>(OnClosedException()); inputResult = folly::Try<InputValueType>(OnClosedException());
} }
auto outputGen = folly::makeTryWith( auto outputGen = folly::makeTryWith(
[&]() { return transformValue_(std::move(inputResult)); }); [&]() { return transformValue_(std::move(inputResult)); });
...@@ -265,8 +266,8 @@ class TransformProcessorBase : public IChannelCallback { ...@@ -265,8 +266,8 @@ class TransformProcessorBase : public IChannelCallback {
return detail::getSenderState(sender_.get()); return detail::getSenderState(sender_.get());
} }
ChannelBridgePtr<TInputValue> receiver_; ChannelBridgePtr<InputValueType> receiver_;
ChannelBridgePtr<TOutputValue> sender_; ChannelBridgePtr<OutputValueType> sender_;
folly::Executor::KeepAlive<folly::SequencedExecutor> executor_; folly::Executor::KeepAlive<folly::SequencedExecutor> executor_;
TransformValueFunc transformValue_; TransformValueFunc transformValue_;
}; };
...@@ -277,16 +278,18 @@ class TransformProcessorBase : public IChannelCallback { ...@@ -277,16 +278,18 @@ class TransformProcessorBase : public IChannelCallback {
* function). * function).
*/ */
template < template <
typename TInputValue, typename InputValueType,
typename TOutputValue, typename OutputValueType,
typename TransformValueFunc> typename TransformValueFunc>
class TransformProcessor : public TransformProcessorBase< class TransformProcessor : public TransformProcessorBase<
TInputValue, InputValueType,
TOutputValue, OutputValueType,
TransformValueFunc> { TransformValueFunc> {
public: public:
using Base = using Base = TransformProcessorBase<
TransformProcessorBase<TInputValue, TOutputValue, TransformValueFunc>; InputValueType,
OutputValueType,
TransformValueFunc>;
using Base::Base; using Base::Base;
private: private:
...@@ -314,20 +317,22 @@ class TransformProcessor : public TransformProcessorBase< ...@@ -314,20 +317,22 @@ class TransformProcessor : public TransformProcessorBase<
* the resumableTransform function. * the resumableTransform function.
*/ */
template < template <
typename TInputValue, typename InputValueType,
typename TOutputValue, typename OutputValueType,
typename InitializeTransformFunc, typename InitializeTransformFunc,
typename TransformValueFunc> typename TransformValueFunc>
class ResumableTransformProcessor : public TransformProcessorBase< class ResumableTransformProcessor : public TransformProcessorBase<
TInputValue, InputValueType,
TOutputValue, OutputValueType,
TransformValueFunc> { TransformValueFunc> {
public: public:
using Base = using Base = TransformProcessorBase<
TransformProcessorBase<TInputValue, TOutputValue, TransformValueFunc>; InputValueType,
OutputValueType,
TransformValueFunc>;
ResumableTransformProcessor( ResumableTransformProcessor(
Sender<TOutputValue> sender, Sender<OutputValueType> sender,
folly::Executor::KeepAlive<folly::SequencedExecutor> executor, folly::Executor::KeepAlive<folly::SequencedExecutor> executor,
InitializeTransformFunc initializeTransform, InitializeTransformFunc initializeTransform,
TransformValueFunc transformValue) TransformValueFunc transformValue)
...@@ -419,17 +424,17 @@ class ResumableTransformProcessor : public TransformProcessorBase< ...@@ -419,17 +424,17 @@ class ResumableTransformProcessor : public TransformProcessorBase<
} // namespace detail } // namespace detail
template < template <
typename TReceiver, typename ReceiverType,
typename TransformValueFunc, typename TransformValueFunc,
typename TInputValue, typename InputValueType,
typename TOutputValue> typename OutputValueType>
Receiver<TOutputValue> transform( Receiver<OutputValueType> transform(
TReceiver inputReceiver, ReceiverType inputReceiver,
folly::Executor::KeepAlive<folly::SequencedExecutor> executor, folly::Executor::KeepAlive<folly::SequencedExecutor> executor,
TransformValueFunc transformValue) { TransformValueFunc transformValue) {
auto [outputReceiver, outputSender] = Channel<TOutputValue>::create(); auto [outputReceiver, outputSender] = Channel<OutputValueType>::create();
using TProcessor = using TProcessor = detail::
detail::TransformProcessor<TInputValue, TOutputValue, TransformValueFunc>; TransformProcessor<InputValueType, OutputValueType, TransformValueFunc>;
auto* processor = new TProcessor( auto* processor = new TProcessor(
std::move(outputSender), std::move(executor), std::move(transformValue)); std::move(outputSender), std::move(executor), std::move(transformValue));
processor->startTransform(std::move(inputReceiver)); processor->startTransform(std::move(inputReceiver));
...@@ -439,17 +444,17 @@ Receiver<TOutputValue> transform( ...@@ -439,17 +444,17 @@ Receiver<TOutputValue> transform(
template < template <
typename InitializeTransformFunc, typename InitializeTransformFunc,
typename TransformValueFunc, typename TransformValueFunc,
typename TReceiver, typename ReceiverType,
typename TInputValue, typename InputValueType,
typename TOutputValue> typename OutputValueType>
Receiver<TOutputValue> resumableTransform( Receiver<OutputValueType> resumableTransform(
folly::Executor::KeepAlive<folly::SequencedExecutor> executor, folly::Executor::KeepAlive<folly::SequencedExecutor> executor,
InitializeTransformFunc initializeTransformFunc, InitializeTransformFunc initializeTransformFunc,
TransformValueFunc transformValue) { TransformValueFunc transformValue) {
auto [outputReceiver, outputSender] = Channel<TOutputValue>::create(); auto [outputReceiver, outputSender] = Channel<OutputValueType>::create();
using TProcessor = detail::ResumableTransformProcessor< using TProcessor = detail::ResumableTransformProcessor<
TInputValue, InputValueType,
TOutputValue, OutputValueType,
InitializeTransformFunc, InitializeTransformFunc,
TransformValueFunc>; TransformValueFunc>;
auto* processor = new TProcessor( auto* processor = new TProcessor(
......
...@@ -26,8 +26,8 @@ namespace channels { ...@@ -26,8 +26,8 @@ namespace channels {
* Returns an output receiver that applies a given transformation function to * Returns an output receiver that applies a given transformation function to
* each value from an input receiver. * each value from an input receiver.
* *
* The TransformValue function takes a Try<TInputValue>, and returns a * The TransformValue function takes a Try<InputValueType>, and returns a
* folly::coro::AsyncGenerator<TOutputValue>. * folly::coro::AsyncGenerator<OutputValueType>.
* *
* - If the TransformValue function yields one or more output values, those * - If the TransformValue function yields one or more output values, those
* output values are sent to the output receiver. * output values are sent to the output receiver.
...@@ -68,21 +68,21 @@ namespace channels { ...@@ -68,21 +68,21 @@ namespace channels {
* }); * });
*/ */
template < template <
typename TReceiver, typename ReceiverType,
typename TransformValueFunc, typename TransformValueFunc,
typename TInputValue = typename TReceiver::ValueType, typename InputValueType = typename ReceiverType::ValueType,
typename TOutputValue = typename folly::invoke_result_t< typename OutputValueType = typename folly::invoke_result_t<
TransformValueFunc, TransformValueFunc,
folly::Try<TInputValue>>::value_type> folly::Try<InputValueType>>::value_type>
Receiver<TOutputValue> transform( Receiver<OutputValueType> transform(
TReceiver inputReceiver, ReceiverType inputReceiver,
folly::Executor::KeepAlive<folly::SequencedExecutor> executor, folly::Executor::KeepAlive<folly::SequencedExecutor> executor,
TransformValueFunc transformValue); TransformValueFunc transformValue);
/** /**
* This function is similar to the above transform function. However, instead of * This function is similar to the above transform function. However, instead of
* taking a single input receiver, it takes an initialization function that * taking a single input receiver, it takes an initialization function that
* returns a std::pair<std::vector<TOutputValue>, Receiver<TInputValue>>. * returns a std::pair<std::vector<OutputValueType>, Receiver<InputValueType>>.
* *
* - If the InitializeTransform function returns successfully, the vector's * - If the InitializeTransform function returns successfully, the vector's
* output values will be immediately sent to the output receiver. The input * output values will be immediately sent to the output receiver. The input
...@@ -130,13 +130,13 @@ Receiver<TOutputValue> transform( ...@@ -130,13 +130,13 @@ Receiver<TOutputValue> transform(
template < template <
typename InitializeTransformFunc, typename InitializeTransformFunc,
typename TransformValueFunc, typename TransformValueFunc,
typename TReceiver = typename folly::invoke_result_t< typename ReceiverType = typename folly::invoke_result_t<
InitializeTransformFunc>::StorageType::second_type, InitializeTransformFunc>::StorageType::second_type,
typename TInputValue = typename TReceiver::ValueType, typename InputValueType = typename ReceiverType::ValueType,
typename TOutputValue = typename folly::invoke_result_t< typename OutputValueType = typename folly::invoke_result_t<
TransformValueFunc, TransformValueFunc,
folly::Try<TInputValue>>::value_type> folly::Try<InputValueType>>::value_type>
Receiver<TOutputValue> resumableTransform( Receiver<OutputValueType> resumableTransform(
folly::Executor::KeepAlive<folly::SequencedExecutor> executor, folly::Executor::KeepAlive<folly::SequencedExecutor> executor,
InitializeTransformFunc initializeTransform, InitializeTransformFunc initializeTransform,
TransformValueFunc transformValue); TransformValueFunc transformValue);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment