diff --git a/fluent/Continuable.h b/fluent/Continuable.h index 8a831f6..dad40c6 100644 --- a/fluent/Continuable.h +++ b/fluent/Continuable.h @@ -202,15 +202,28 @@ namespace detail }, std::move(*this)); } - /* - // TODO Accept only correct callbacks + /// Placeholder template - Continuable> all(_CTy&&...) + _ContinuableImpl& all(_CTy&&...) { - // TODO Transmute the returned callback here. - return Continuable>(std::move(*this)); + return *this; + } + + /// Placeholder + template + _ContinuableImpl& some(size_t const count, _CTy&&...) + { + return *this; + } + + /// Placeholder + template + auto any(_CTy&&... functionals) + -> decltype(some(1, std::declval<_CTy>()...)) + { + // Equivalent to invoke `some` with count 1. + return some(1, std::forward<_CTy>(functionals)...); } - */ /* /// Validates the Continuable @@ -307,4 +320,19 @@ inline auto make_continuable(_FTy&& functional) return detail::continuable_factory_t<_FTy>::CreateFrom(std::forward<_FTy>(functional)); } +/// Creates an empty continuable. +/// Can be used to start a chain with aggregate methods. +/// empty_continuable() +/// .all(...) +/// .some(...) +/// .any(...) +inline auto empty_continuable() + -> Continuable<> +{ + return make_continuable([](Callback<>&& callback) + { + callback(); + }); +} + #endif // _CONTINUABLE_H_ diff --git a/test.cpp b/test.cpp index 6e6787c..39eabcd 100644 --- a/test.cpp +++ b/test.cpp @@ -44,6 +44,18 @@ Continuable CastSpellPromise(int id) }); } +// Void instant returning continuable promise for testing purposes +Continuable<> TrivialPromise(std::string const& msg = "") +{ + return make_continuable([=](Callback<>&& callback) + { + if (!msg.empty()) + std::cout << msg << std::endl; + + callback(); + }); +} + Continuable Validate() { return make_continuable([=](Callback&& callback) @@ -84,6 +96,26 @@ int main(int /*argc*/, char** /*argv*/) return Validate(); }); + // Mockup of aggregate methods + empty_continuable() + .all( + [] { return TrivialPromise(); }, + [] { return TrivialPromise(); }, + [] { return TrivialPromise(); } + ) + .some(2, // Only 2 of 3 must complete + [] { return TrivialPromise(); }, + [] { return TrivialPromise(); }, + [] { return TrivialPromise(); } + ) + .any( // Any of 2. + [] { return TrivialPromise(); }, + [] { return TrivialPromise(); } + ) + .then([] + { + }); + //Continuable cb = make_continuable([](Callback&& callback) //{