mockups of new methods

This commit is contained in:
Naios 2015-06-16 17:51:04 +02:00
parent e002775e92
commit aff69c5aa4
2 changed files with 66 additions and 6 deletions

View File

@ -202,15 +202,28 @@ namespace detail
}, std::move(*this));
}
/*
// TODO Accept only correct callbacks
/// Placeholder
template<typename... _CTy>
Continuable<Callback<_ATy...>> all(_CTy&&...)
_ContinuableImpl& all(_CTy&&...)
{
// TODO Transmute the returned callback here.
return Continuable<Callback<_ATy...>>(std::move(*this));
return *this;
}
/// Placeholder
template<typename... _CTy>
_ContinuableImpl& some(size_t const count, _CTy&&...)
{
return *this;
}
/// Placeholder
template<typename... _CTy>
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_

View File

@ -44,6 +44,18 @@ Continuable<SpellCastResult> 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<bool> Validate()
{
return make_continuable([=](Callback<bool>&& 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<bool> cb = make_continuable([](Callback<bool>&& callback)
//{