9 #include <lager/store.hpp>
28 template<
class EventLoop,
class Xform,
class ...Enhancers>
34 using CursorT = lager::reader<ModelT>;
35 using CursorTSP = std::shared_ptr<CursorT>;
37 using StoreT = decltype(
39 std::declval<ModelT>(),
41 std::declval<EventLoop>(),
43 std::ref(detail::declref<JobInterface>()),
44 std::ref(detail::declref<EventInterface>()),
45 lager::dep::as<SdkModelCursorKey>(std::declval<std::function<CursorTSP()>>()),
46 std::ref(detail::declref<RandomInterface>())
47 #ifdef KAZV_USE_THREAD_SAFETY_HELPER
48 , std::ref(detail::declref<EventLoopThreadIdKeeper>())
51 std::declval<Enhancers>()...)
55 #ifdef KAZV_USE_THREAD_SAFETY_HELPER
56 , EventLoopThreadIdKeeper &
65 EventLoop &&eventLoop,
67 Enhancers &&...enhancers)
69 std::move(model), jobHandler, eventEmitter,
70 std::forward<EventLoop>(eventLoop),
std::forward<Xform>(xform),
71 std::forward<Enhancers>(enhancers)...)) {}
104 auto secondaryStore = lager::make_store<ModelT>(
105 std::move(initialModel),
106 std::forward<EL>(eventLoop),
107 lager::with_reducer([](
auto &&,
auto next) {
return next; }));
109 lager::context<ModelT> secondaryCtx = secondaryStore;
112 .then([secondaryCtx, d=m_d.get()](
auto &&) {
113 lager::watch(*(d->sdk),
114 [secondaryCtx](auto next) { secondaryCtx.dispatch(std::move(next)); });
117 return secondaryStore;
142 EventLoop &&eventLoop,
144 Enhancers &&...enhancers)
146 , store(makeStore<ActionT>(
149 std::forward<EventLoop>(eventLoop),
151 std::ref(jobHandler),
152 std::ref(eventEmitter),
153 lager::dep::as<SdkModelCursorKey>(
154 std::function<CursorTSP()>([
this] {
return sdk; })),
156 #ifdef KAZV_USE_THREAD_SAFETY_HELPER
160 std::forward<Enhancers>(enhancers)...))
161 , sdk(std::make_shared<lager::reader<ModelT>>(store.reader().xform(std::forward<Xform>(xform))))
163 #ifdef KAZV_USE_THREAD_SAFETY_HELPER
164 store.context().createResolvedPromise(EffectStatus{})
165 .then([
this](
auto &&) {
166 keeper.set(std::this_thread::get_id());
170 #ifdef KAZV_USE_THREAD_SAFETY_HELPER
171 EventLoopThreadIdKeeper keeper;
173 std::optional<RandomInterface> rg;
178 std::unique_ptr<Private> m_d;
199 template<
class EventLoop,
class Xform,
class ...Enhancers>
203 EventLoop &&eventLoop,
205 Enhancers &&...enhancers)
206 ->
Sdk<EventLoop, Xform, Enhancers...>
208 return { std::move(sdk),
211 std::forward<EventLoop>(eventLoop),
212 std::forward<Xform>(xform),
213 std::forward<Enhancers>(enhancers)... };
221 return Crypto::constructRandomSize();
224 template<
class EventLoop,
class Xform,
class ...Enhancers>
225 [[deprecated(
"Use deterministic makeDefaultSdkWithCryptoRandom instead. In the future, this will be removed.")]]
229 EventLoop &&eventLoop,
231 Enhancers &&...enhancers)
232 ->
Sdk<EventLoop, Xform, Enhancers...>
240 std::forward<EventLoop>(eventLoop),
241 std::forward<Xform>(xform),
242 std::forward<Enhancers>(enhancers)...);
265 template<
class PH,
class Xform,
class ...Enhancers>
272 Enhancers &&...enhancers)
273 ->
Sdk<PH, Xform, Enhancers...>
281 std::forward<PH>(ph),
282 std::forward<Xform>(xform),
283 std::forward<Enhancers>(enhancers)...);
296 return lager::with_deps(std::ref(random));