mirror of
https://github.com/Naios/continuable.git
synced 2025-12-08 01:36:46 +08:00
mockups of new methods
This commit is contained in:
parent
158da9d3ce
commit
31956d9f8e
@ -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_
|
||||
|
||||
32
test.cpp
32
test.cpp
@ -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)
|
||||
//{
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user