|
proxygen
|
#include <BatchDispatcher.h>
Classes | |
| struct | DispatchState |
Public Types | |
| using | ValueBatchT = std::vector< ValueT > |
| using | ResultBatchT = std::vector< ResultT > |
| using | PromiseBatchT = std::vector< folly::Promise< ResultT >> |
| using | DispatchFunctionT = folly::Function< ResultBatchT(ValueBatchT &&)> |
Public Member Functions | |
| BatchDispatcher (ExecutorT &executor, DispatchFunctionT dispatchFunc) | |
| Future< ResultT > | add (ValueT value) |
Static Private Member Functions | |
| static void | dispatchFunctionWrapper (DispatchState &state) |
Private Attributes | |
| ExecutorT & | executor_ |
| std::shared_ptr< DispatchState > | state_ |
BatchDispatcher is useful for batching values while doing I/O. For example, if you are launching multiple tasks which take a single id and each task fetches from database, you can use BatchDispatcher to batch those ids and do a single query requesting all those ids.
To use this, create a BatchDispatcher with a dispatch function which consumes a vector of values and returns a vector of results in the same order. Add values to BatchDispatcher using add function, which returns a future to the result set in your dispatch function.
Implementation Logic:
Example:
Note:
Definition at line 72 of file BatchDispatcher.h.
| using folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::DispatchFunctionT = folly::Function<ResultBatchT(ValueBatchT&&)> |
Definition at line 77 of file BatchDispatcher.h.
| using folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::PromiseBatchT = std::vector<folly::Promise<ResultT>> |
Definition at line 76 of file BatchDispatcher.h.
| using folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::ResultBatchT = std::vector<ResultT> |
Definition at line 75 of file BatchDispatcher.h.
| using folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::ValueBatchT = std::vector<ValueT> |
Definition at line 74 of file BatchDispatcher.h.
|
inline |
Definition at line 79 of file BatchDispatcher.h.
|
inline |
Definition at line 83 of file BatchDispatcher.h.
References folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::dispatchFunctionWrapper(), folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::executor_, folly::Promise< T >::getFuture(), folly::gen::move, and folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::state_.
Referenced by doubleBatchInnerDispatch(), doubleBatchOuterDispatch(), and singleBatchDispatch().
|
inlinestaticprivate |
Definition at line 107 of file BatchDispatcher.h.
References folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::DispatchState::dispatchFunc, i, folly::gen::move, folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::DispatchState::promises, and folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::DispatchState::values.
Referenced by folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::add().
|
private |
Definition at line 135 of file BatchDispatcher.h.
Referenced by folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::add().
|
private |
Definition at line 136 of file BatchDispatcher.h.
Referenced by folly::fibers::BatchDispatcher< ValueT, ResultT, ExecutorT >::add().